Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default Subscript out of range error - selecting a sheet

Why does this fail? The codename for my sheet is wsh1:

Dim c as integer
c = 1
sheets ("wsh" & c).select

It fails with the error message "subscript out of range. "


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Subscript out of range error - selecting a sheet

Where is the code located?

The codenaem of the sheet cannot be changed it is read only. It is usually
Sheet1 and in the VBA project window would be the name not in parenthesis.
To access by code name would be someithing like this

Dim c as integer
c = 1
sheets1.select

If you are using the sheet name in parenthesis then you must have the name
typed incorrectly. You could have extra spaces on the tab which may be
causing the problem.



"John" wrote:

Why does this fail? The codename for my sheet is wsh1:

Dim c as integer
c = 1
sheets ("wsh" & c).select

It fails with the error message "subscript out of range. "



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default Subscript out of range error - selecting a sheet

The code is located in a module. This is actually a stripped down part of my
code - I'm trying to do a "for loop" and I want to loop through wsh1 through
wsh24 (these are code names, not sheet names).

"Joel" wrote in message
...
Where is the code located?

The codenaem of the sheet cannot be changed it is read only. It is
usually
Sheet1 and in the VBA project window would be the name not in parenthesis.
To access by code name would be someithing like this

Dim c as integer
c = 1
sheets1.select

If you are using the sheet name in parenthesis then you must have the name
typed incorrectly. You could have extra spaces on the tab which may be
causing the problem.



"John" wrote:

Why does this fail? The codename for my sheet is wsh1:

Dim c as integer
c = 1
sheets ("wsh" & c).select

It fails with the error message "subscript out of range. "





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Subscript out of range error - selecting a sheet

Your original example didn't give us a lot to go on as to what you are
trying to do, so let me try and give you an overall approach to try out. By
the way, it is almost always a bad idea to simplify your code for
presentation to the newsgroups... doing so almost always forces you to
return to ask us how to modify code offered to you for your actual setup.

Dim ShtNum As Long
Dim WS As Worksheet
......
......
For Each WS In Worksheets
If LCase(WS.Name) Like "wsh#*" Then
If Mid(WS.Name, 4) <= 24 Then
WS.Select
' Rest of your code goes here
End If
End If
Next

--
Rick (MVP - Excel)


"John" wrote in message
...
The code is located in a module. This is actually a stripped down part of
my code - I'm trying to do a "for loop" and I want to loop through wsh1
through wsh24 (these are code names, not sheet names).

"Joel" wrote in message
...
Where is the code located?

The codenaem of the sheet cannot be changed it is read only. It is
usually
Sheet1 and in the VBA project window would be the name not in
parenthesis.
To access by code name would be someithing like this

Dim c as integer
c = 1
sheets1.select

If you are using the sheet name in parenthesis then you must have the
name
typed incorrectly. You could have extra spaces on the tab which may be
causing the problem.



"John" wrote:

Why does this fail? The codename for my sheet is wsh1:

Dim c as integer
c = 1
sheets ("wsh" & c).select

It fails with the error message "subscript out of range. "






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
Copying Sheet - subscript out of range error GSP@DCS Excel Programming 1 August 2nd 06 01:56 AM
Runtime Error - Subscript out of range despite On Error statement DoctorG Excel Programming 3 July 28th 06 03:56 PM
Subscript out of range error - save copy error bg18461[_15_] Excel Programming 1 June 13th 06 04:36 PM
In multiple sheet copy error subscript out of range ?? HELP Eddy Stan Excel Programming 4 March 22nd 06 04:54 AM
Type Mismatch error & subscript out of range error Jeff Wright[_2_] Excel Programming 3 May 14th 05 07:14 PM


All times are GMT +1. The time now is 12:24 AM.

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

About Us

"It's about Microsoft Excel"