Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
AL AL is offline
external usenet poster
 
Posts: 37
Default Subscript Out of Range

I'm trying to copy out worksheets Tab1 and Tab2 but am
receiving a subscript out of range error. The Worksheets
do exist and the code is attached below.

I've simplified this problem, as I do need a Variable
to denote which worksheets will be copied out.

(Otherwise I could have used
Sheets(Array("Tab1","Tab2")).Copy
which works)


Sub test()
Dim s As String

s = """" & "Tab1" & """" & ", " & """" & "Tab2" & """"
Sheets(Array(s)).Copy
End Sub

Thanks in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Subscript Out of Range

Sub Test
dim list(0 to 1)
list(0) = "Tab1"
list(1) = "Tab2"
sheets(list).copy
End Test

--
Regards,
Tom Ogilvy


"Al" wrote in message
...
I'm trying to copy out worksheets Tab1 and Tab2 but am
receiving a subscript out of range error. The Worksheets
do exist and the code is attached below.

I've simplified this problem, as I do need a Variable
to denote which worksheets will be copied out.

(Otherwise I could have used
Sheets(Array("Tab1","Tab2")).Copy
which works)


Sub test()
Dim s As String

s = """" & "Tab1" & """" & ", " & """" & "Tab2" & """"
Sheets(Array(s)).Copy
End Sub

Thanks in advance.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 64
Default Subscript Out of Range

Al,
the problem is that the SHEETS(ARRAY(..)) is looking for
an array of values and you are sending a single value
(your variable, "s") which has been manipulated to equal
the same value as the basic ARRAY(..), but isn't an array.

Are there only ever two sheets to copy, and where do the
names come from? If there are always the same number of
sheets, you could just use two variables, or make "s" an
array and the two sheet names subscripts of this:

Sheets(array(s,t)).copy
Sheets(array(s(1),s(2))).copy

Cheers, Pete

-----Original Message-----
I'm trying to copy out worksheets Tab1 and Tab2 but am
receiving a subscript out of range error. The Worksheets
do exist and the code is attached below.

I've simplified this problem, as I do need a Variable
to denote which worksheets will be copied out.

(Otherwise I could have used
Sheets(Array("Tab1","Tab2")).Copy
which works)


Sub test()
Dim s As String

s = """" & "Tab1" & """" & ", " & """" & "Tab2" & """"
Sheets(Array(s)).Copy
End Sub

Thanks in advance.
.

  #4   Report Post  
Posted to microsoft.public.excel.programming
AL AL is offline
external usenet poster
 
Posts: 37
Default Subscript Out of Range

Many Thanks Tom, your utilization of arrays provides for a
very efficient solution.


-----Original Message-----
Sub Test
dim list(0 to 1)
list(0) = "Tab1"
list(1) = "Tab2"
sheets(list).copy
End Test

--
Regards,
Tom Ogilvy


"Al" wrote in

message
...
I'm trying to copy out worksheets Tab1 and Tab2 but am
receiving a subscript out of range error. The

Worksheets
do exist and the code is attached below.

I've simplified this problem, as I do need a Variable
to denote which worksheets will be copied out.

(Otherwise I could have used
Sheets(Array("Tab1","Tab2")).Copy
which works)


Sub test()
Dim s As String

s = """" & "Tab1" & """" & ", " & """" & "Tab2" & """"
Sheets(Array(s)).Copy
End Sub

Thanks in advance.



.

  #5   Report Post  
Posted to microsoft.public.excel.programming
AL AL is offline
external usenet poster
 
Posts: 37
Default Subscript Out of Range

Pete:

Thanks for pointing out the flaw in my code. I now know
what I did wrong and have been able to fix it with yours
and Toms help.

I'm now using a countif statement to determine the upper
bound of my array (the solution Tom provided)

And then using the redim statement and a loop to fill it
accordingly.

-----Original Message-----
Al,
the problem is that the SHEETS(ARRAY(..)) is looking for
an array of values and you are sending a single value
(your variable, "s") which has been manipulated to equal
the same value as the basic ARRAY(..), but isn't an array.

Are there only ever two sheets to copy, and where do the
names come from? If there are always the same number of
sheets, you could just use two variables, or make "s" an
array and the two sheet names subscripts of this:

Sheets(array(s,t)).copy
Sheets(array(s(1),s(2))).copy

Cheers, Pete

-----Original Message-----
I'm trying to copy out worksheets Tab1 and Tab2 but am
receiving a subscript out of range error. The

Worksheets
do exist and the code is attached below.

I've simplified this problem, as I do need a Variable
to denote which worksheets will be copied out.

(Otherwise I could have used
Sheets(Array("Tab1","Tab2")).Copy
which works)


Sub test()
Dim s As String

s = """" & "Tab1" & """" & ", " & """" & "Tab2" & """"
Sheets(Array(s)).Copy
End Sub

Thanks in advance.
.

.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 863
Default Subscript Out of Range

Since you probably don't have a sheet named "Tab1","Tab2", the code fails.

Your code creates a single string consisting of a list of tab names, delimited
by commas. It doesn't create an array with one tab name in each element. As
you know, it's the array statement that does that.

What is the problem with using the statement that you know works?


On Wed, 22 Sep 2004 06:26:05 -0700, "Al"
wrote:

I'm trying to copy out worksheets Tab1 and Tab2 but am
receiving a subscript out of range error. The Worksheets
do exist and the code is attached below.

I've simplified this problem, as I do need a Variable
to denote which worksheets will be copied out.

(Otherwise I could have used
Sheets(Array("Tab1","Tab2")).Copy
which works)


Sub test()
Dim s As String

s = """" & "Tab1" & """" & ", " & """" & "Tab2" & """"
Sheets(Array(s)).Copy
End Sub

Thanks in advance.


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
Subscript out of range OKHM Excel Discussion (Misc queries) 0 August 6th 09 05:18 PM
subscript out of range Todd Huttenstine[_3_] Excel Programming 1 June 11th 04 04:08 AM
Subscript out of range? Jason Hancock Excel Programming 3 May 26th 04 07:11 PM
Subscript out of range Ed Excel Programming 1 February 5th 04 07:17 PM
SubScript Out Of Range. Sam Excel Programming 4 December 21st 03 02:10 AM


All times are GMT +1. The time now is 09:20 PM.

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"