Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Array from row in worksheet

Hi All,

I am trying to dynamically copy named sheets to a new workbook. The
following works perfectly:

Products = Array("Apple", "Banana", "Orange")
Sheets(Products).Copy

This copies the worksheets Apple, Banana and Orange to a new workbook.
What I am trying to do is dynamically populate the array. I have the
following code to do so:

Dim Products
i = 1

'Get the number of products
Do While ActiveCell.Offset(0, i).Value < ""
i = i + 1
Loop

'Redefine the array size to number of products
ReDim Products((i-1))
'Reset the counter
i = 0

'Populate the array
Do While ActiveCell.Offset(0, i).Value < ""
Products(i) = ActiveCell.Offset(0, i).Value
i = i + 1
Loop

Sheets(Products).Copy

- The code above should redefine the array to add Apple, Banana and
Orange in to position 1, 2, and 3 in the array respectively. The error
message I receive from: Sheets(Products).Copy is:

Run-time error '9':

Subscript out of range

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Array from row in worksheet

Probably due to this section
'Populate the array
Do While ActiveCell.Offset(0, i).Value < ""
Products(i) = ActiveCell.Offset(0, i).Value
i = i + 1
Loop


The "i" in Products(i) - might be getting to big - worth investigating.

Scott

"Colin Nederkoorn" wrote in message
oups.com...
Hi All,

I am trying to dynamically copy named sheets to a new workbook. The
following works perfectly:

Products = Array("Apple", "Banana", "Orange")
Sheets(Products).Copy

This copies the worksheets Apple, Banana and Orange to a new workbook.
What I am trying to do is dynamically populate the array. I have the
following code to do so:

Dim Products
i = 1

'Get the number of products
Do While ActiveCell.Offset(0, i).Value < ""
i = i + 1
Loop

'Redefine the array size to number of products
ReDim Products((i-1))
'Reset the counter
i = 0

'Populate the array
Do While ActiveCell.Offset(0, i).Value < ""
Products(i) = ActiveCell.Offset(0, i).Value
i = i + 1
Loop

Sheets(Products).Copy

- The code above should redefine the array to add Apple, Banana and
Orange in to position 1, 2, and 3 in the array respectively. The error
message I receive from: Sheets(Products).Copy is:

Run-time error '9':

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
How to Read Worksheet Data into VBA Array? Peter Bernadyne Excel Discussion (Misc queries) 1 July 12th 06 05:19 PM
Selecting Worksheet Array JEFF Excel Programming 5 May 31st 06 04:05 PM
Writing values to worksheet from array interstellar Excel Programming 6 September 12th 05 07:00 PM
Paste Array into worksheet Kaval Excel Programming 1 August 11th 05 09:18 AM
Array of Values from Worksheet Range - What does it 'look' like? Alan Excel Programming 7 July 8th 04 01:06 PM


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