#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 190
Default sheet name

hi,

I have the following:

For x = 1 to 30
dim previoussheet as string
previoussheet = "acct" & x-1
set sh = worksheets(previoussheet)

if not sheetexists(sh) then
....

i think there is a problem with the following line:
set sh = worksheets(previoussheet)
because the standard syntax is usually something like:
set sh = worksheets("previoussheet")

i am not sure what to do. could someone help?

thanks in advance,
geebee


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default sheet name

If I understand your question, one way:

Dim sh As Worksheet
Dim x As Long

For x = 1 To 30
On Error Resume Next
Set sh = Worksheets("acct" & x - 1)
On Error GoTo 0
If Not sh Is Nothing Then
' do stuff
End If
Set sh = Nothing
Next x



In article ,
geebee (noSPAMs) wrote:

hi,

I have the following:

For x = 1 to 30
dim previoussheet as string
previoussheet = "acct" & x-1
set sh = worksheets(previoussheet)

if not sheetexists(sh) then
...

i think there is a problem with the following line:
set sh = worksheets(previoussheet)
because the standard syntax is usually something like:
set sh = worksheets("previoussheet")

i am not sure what to do. could someone help?

thanks in advance,
geebee

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 190
Default sheet name

i,
I am getting a "subscript out of range" error pointing to the
Set sh = Worksheets("acct" & x - 1)
line.

geebee

"JE McGimpsey" wrote:

If I understand your question, one way:

Dim sh As Worksheet
Dim x As Long

For x = 1 To 30
On Error Resume Next
Set sh = Worksheets("acct" & x - 1)
On Error GoTo 0
If Not sh Is Nothing Then
' do stuff
End If
Set sh = Nothing
Next x



In article ,
geebee (noSPAMs) wrote:

hi,

I have the following:

For x = 1 to 30
dim previoussheet as string
previoussheet = "acct" & x-1
set sh = worksheets(previoussheet)

if not sheetexists(sh) then
...

i think there is a problem with the following line:
set sh = worksheets(previoussheet)
because the standard syntax is usually something like:
set sh = worksheets("previoussheet")

i am not sure what to do. could someone help?

thanks in advance,
geebee


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default sheet name

Do you have a sheet named acct0? If not, you will get the error message. I
wondered about that when I saw the x-1. Also make sure the Set statement is
inside the For loop.

"geebee" wrote:

i,
I am getting a "subscript out of range" error pointing to the
Set sh = Worksheets("acct" & x - 1)
line.

geebee

"JE McGimpsey" wrote:

If I understand your question, one way:

Dim sh As Worksheet
Dim x As Long

For x = 1 To 30
On Error Resume Next
Set sh = Worksheets("acct" & x - 1)
On Error GoTo 0
If Not sh Is Nothing Then
' do stuff
End If
Set sh = Nothing
Next x



In article ,
geebee (noSPAMs) wrote:

hi,

I have the following:

For x = 1 to 30
dim previoussheet as string
previoussheet = "acct" & x-1
set sh = worksheets(previoussheet)

if not sheetexists(sh) then
...

i think there is a problem with the following line:
set sh = worksheets(previoussheet)
because the standard syntax is usually something like:
set sh = worksheets("previoussheet")

i am not sure what to do. could someone help?

thanks in advance,
geebee


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default sheet name

Since the code I gave you has that line right after

On Error Resume Next

which tells VBA to ignore any errors, I'll assume that you've modified
it somehow. Posting the code you actually used may help...

In article ,
geebee (noSPAMs) wrote:

i,
I am getting a "subscript out of range" error pointing to the
Set sh = Worksheets("acct" & x - 1)
line.

geebee

"JE McGimpsey" wrote:

If I understand your question, one way:

Dim sh As Worksheet
Dim x As Long

For x = 1 To 30
On Error Resume Next
Set sh = Worksheets("acct" & x - 1)
On Error GoTo 0
If Not sh Is Nothing Then
' do stuff
End If
Set sh = Nothing
Next x

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
excel sheet bootom half sheet goes behind top part of sheet rob Excel Worksheet Functions 2 January 17th 09 01:28 AM
Duplicate sheet, autonumber sheet, record data on another sheet des-sa[_2_] Excel Worksheet Functions 0 May 8th 08 06:56 PM
Export sheet store sheet import sheet. Robert[_33_] Excel Programming 0 December 28th 06 01:58 PM
Copying cells from on sheet to another sheet (via sheet module) CRayF Excel Programming 6 September 20th 05 08:58 PM
Inserting a row in sheet A should Insert a row in sheet B, removing a row in Sheet A should remove the corresponding row in sheet B Hannes Heckner Excel Programming 1 March 5th 04 09:10 AM


All times are GMT +1. The time now is 03: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"