ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Select worksheet using a variable (https://www.excelbanter.com/excel-programming/417036-select-worksheet-using-variable.html)

Neal Ostrander

Select worksheet using a variable
 
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

Bob Phillips[_3_]

Select worksheet using a variable
 
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.

--
__________________________________
HTH

Bob

"Neal Ostrander" wrote in message
...
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




Sheeloo[_2_]

Select worksheet using a variable
 
You have not assigned any value to the variable sheetName before using it...
Try
Dim sheetName

sheetName = "Name of your sheet here"
Sheets(sheetName).Select



"Neal Ostrander" wrote:

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



All times are GMT +1. The time now is 12:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com