Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 364
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using a variable to select a cell on a worksheet..."Subscript out orrange" Zarlot Excel Programming 4 May 28th 08 07:27 PM
select cell by variable name Adam Excel Discussion (Misc queries) 6 May 20th 08 07:54 PM
worksheet select using variable Kryer Excel Programming 3 November 11th 05 12:17 AM
In Excel 2000, How do you select the whole of a worksheet (Select. Rascal Excel Discussion (Misc queries) 1 March 5th 05 12:03 AM
In Excel 2000, How do you select the whole of a worksheet (Select. Rascal Excel Discussion (Misc queries) 1 March 4th 05 11:59 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"