excel vba activating a tab by name using a variable string -


can please help? have feeling type of issue simple 1 , has been answered many times can't seem find solution works. getting hit error 9: subscript out of range.

a part of frustration due simplicity of code works. have spreadsheet tabs named "dist.12345-store.67890". have vba code open tab if use:

sub test() worksheets("dist.12345-store.67890").visible = true end sub 

but rather hard code string in code 31 times in 31 different subs want put string variable storeselect2, , refer string worksheet appear. error 9...

sub test()  dim storeselect2 string  storeselect2 = "dist." & activecell.offset(0, -1).value & "-store." & activecell.value ` storeselect2 = "dist.12345-store.67890" `  sheets(storeselect2).visible = true  `this error 9 occurs`  end sub 

how can existing tab come when using string refer tab name in code? due string coming 1 tab , trying open another?

thanks!!

this need write

 dim storeselect2 string  dim pig, dog, cat, bird string  pig = "dist."  dog = activecell.offset(0, -1).value  cat = "-store."  bird = activecell.value  storeselect2 = pig & dog & cat & bird  sheets(storeselect2).visible = false 

Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -