Select worksheet using a variable

N

Neal Ostrander

I am trying to copy data from one worksheet into another based on the value
in one of the cells in the original worksheet.
I have declared the variable and set the Sheets.select as follows

Dim sheetName
Sheets(sheetName).Select

when the code gets to the Sheets(sheetName).Select line it gives a Runtime
error and says Subscript out of range. Any ideas why this is happenig and how
to correct it.
Thanks
Neal
 
B

Bob Phillips

It means that there is not a worksheet with the name that is contained
within the variable SheetName. You have either mis-spelt, or not loaded it
into that variable.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top