Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default How do I assign large number of named worksheets to a varArray

how can I assign a large number of named sheets to an array variable
(varArray).
In otherwords if I have a collection of large number of named worksheets
like "ASD","XZC","BNM",.......etc.
I want to assign them to the array variable varArray, like;
varArray = "ASD","XZC",......
Then I want to use it in the following statement :
For each asheet in activeworkbook.sheets(varArray)
Please notice that :
-I want to limit the search to limited number of sheets of the
activeworkbook, but the number of these sheets are relatively large ( more
than 20 sheets).
-I want to assign the sheets to the varArray in one seperate line, so that I
can increase r decrease the number of sheets anytime
-The activeworkbook contains many sheets, but I want to limit the search (
Done by For ...each )to a certain number out of the total sheet number.
-Are there a limit to the number of sheets used with the statement for...
each?
- I am using Excel 2003 and Excel 2007.
Thank you
--
Nabil A Youssef
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default How do I assign large number of named worksheets to a varArray

The following will create an array and assign sheet names to it:

Sub sheetnames()
Dim ary() As String
ReDim ary(1 To Sheets.Count)
For i = 1 To UBound(ary)
ary(i) = Sheets(i).Name
MsgBox (ary(i))
Next
End Sub

But you do not need the sheet names to refer to, or loop over, sheets; just
use the index.
--
Gary''s Student - gsnu200781


"Nabil" wrote:

how can I assign a large number of named sheets to an array variable
(varArray).
In otherwords if I have a collection of large number of named worksheets
like "ASD","XZC","BNM",.......etc.
I want to assign them to the array variable varArray, like;
varArray = "ASD","XZC",......
Then I want to use it in the following statement :
For each asheet in activeworkbook.sheets(varArray)
Please notice that :
-I want to limit the search to limited number of sheets of the
activeworkbook, but the number of these sheets are relatively large ( more
than 20 sheets).
-I want to assign the sheets to the varArray in one seperate line, so that I
can increase r decrease the number of sheets anytime
-The activeworkbook contains many sheets, but I want to limit the search (
Done by For ...each )to a certain number out of the total sheet number.
-Are there a limit to the number of sheets used with the statement for...
each?
- I am using Excel 2003 and Excel 2007.
Thank you
--
Nabil A Youssef

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How do I assign large number of named worksheets to a varArray

A structure like this should do what you want; just put your active code
between the With/End With statements using a leading dot for sheet items so
that item will refer to the currently referred to sheet, like my
..Cells(1,1).Value example....

Dim SH As Variant
Dim MySheets As Variant
MySheets = Array("Sheet1", "Sheet4", "Sheet7")
For Each SH In MySheets
With Sheets(SH)
Debug.Print .Cells(1, 1).Value
End With
Next

Rick


"Nabil" wrote in message
...
how can I assign a large number of named sheets to an array variable
(varArray).
In otherwords if I have a collection of large number of named worksheets
like "ASD","XZC","BNM",.......etc.
I want to assign them to the array variable varArray, like;
varArray = "ASD","XZC",......
Then I want to use it in the following statement :
For each asheet in activeworkbook.sheets(varArray)
Please notice that :
-I want to limit the search to limited number of sheets of the
activeworkbook, but the number of these sheets are relatively large ( more
than 20 sheets).
-I want to assign the sheets to the varArray in one seperate line, so that
I
can increase r decrease the number of sheets anytime
-The activeworkbook contains many sheets, but I want to limit the search (
Done by For ...each )to a certain number out of the total sheet number.
-Are there a limit to the number of sheets used with the statement for...
each?
- I am using Excel 2003 and Excel 2007.
Thank you
--
Nabil A Youssef


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How do I assign large number of named worksheets to a varArray

So there is no confusion with 'shape' of the example names I used, the Array
function assignment statement for example sheet names you posted would be...

MySheets = Array("ASD", "XZC", "BNM")

Just add or remove your sheet names in this statement as needed.

Rick



"Rick Rothstein (MVP - VB)" wrote in
message ...
A structure like this should do what you want; just put your active code
between the With/End With statements using a leading dot for sheet items so
that item will refer to the currently referred to sheet, like my
.Cells(1,1).Value example....

Dim SH As Variant
Dim MySheets As Variant
MySheets = Array("Sheet1", "Sheet4", "Sheet7")
For Each SH In MySheets
With Sheets(SH)
Debug.Print .Cells(1, 1).Value
End With
Next

Rick


"Nabil" wrote in message
...
how can I assign a large number of named sheets to an array variable
(varArray).
In otherwords if I have a collection of large number of named worksheets
like "ASD","XZC","BNM",.......etc.
I want to assign them to the array variable varArray, like;
varArray = "ASD","XZC",......
Then I want to use it in the following statement :
For each asheet in activeworkbook.sheets(varArray)
Please notice that :
-I want to limit the search to limited number of sheets of the
activeworkbook, but the number of these sheets are relatively large (
more
than 20 sheets).
-I want to assign the sheets to the varArray in one seperate line, so
that I
can increase r decrease the number of sheets anytime
-The activeworkbook contains many sheets, but I want to limit the search
(
Done by For ...each )to a certain number out of the total sheet number.
-Are there a limit to the number of sheets used with the statement for...
each?
- I am using Excel 2003 and Excel 2007.
Thank you
--
Nabil A Youssef



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How do I assign large number of named worksheets to a varArray

It just occurred to me, you might be wanting to change (add or remove)
sheets dynamically in code. The Array function does not really lend itself
to doing that. Examine this code snippet instead to see a method of being
able to actively change the number of referred to sheets...

Dim SH As Variant
Dim MySheets As Variant
Dim SheetNames As String
' Hard coded list of names
MySheets = Split("ASD,XZC,BNM", ",")
For Each SH In MySheets
With Sheets(SH)
Debug.Print .Cells(1, 1).Value
End With
Next
' Dynamically assigned list of names
SheetNames = "ASD,XZC,BNM,XXX,YYY,ZZZ"
MySheets = Split(SheetNames, ",")
For Each SH In MySheets
With Sheets(SH)
Debug.Print .Cells(1, 1).Value
End With
Next

Notice the list of names in the first argument of the Split function is a
single, comma delimited String (no internal quote marks).

Rick


"Rick Rothstein (MVP - VB)" wrote in
message ...
A structure like this should do what you want; just put your active code
between the With/End With statements using a leading dot for sheet items so
that item will refer to the currently referred to sheet, like my
.Cells(1,1).Value example....

Dim SH As Variant
Dim MySheets As Variant
MySheets = Array("Sheet1", "Sheet4", "Sheet7")
For Each SH In MySheets
With Sheets(SH)
Debug.Print .Cells(1, 1).Value
End With
Next

Rick


"Nabil" wrote in message
...
how can I assign a large number of named sheets to an array variable
(varArray).
In otherwords if I have a collection of large number of named worksheets
like "ASD","XZC","BNM",.......etc.
I want to assign them to the array variable varArray, like;
varArray = "ASD","XZC",......
Then I want to use it in the following statement :
For each asheet in activeworkbook.sheets(varArray)
Please notice that :
-I want to limit the search to limited number of sheets of the
activeworkbook, but the number of these sheets are relatively large (
more
than 20 sheets).
-I want to assign the sheets to the varArray in one seperate line, so
that I
can increase r decrease the number of sheets anytime
-The activeworkbook contains many sheets, but I want to limit the search
(
Done by For ...each )to a certain number out of the total sheet number.
-Are there a limit to the number of sheets used with the statement for...
each?
- I am using Excel 2003 and Excel 2007.
Thank you
--
Nabil A Youssef





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default How do I assign large number of named worksheets to a varArray

this code also replied my question
thank you
--
Nabil A Youssef


"Rick Rothstein (MVP - VB)" wrote:

It just occurred to me, you might be wanting to change (add or remove)
sheets dynamically in code. The Array function does not really lend itself
to doing that. Examine this code snippet instead to see a method of being
able to actively change the number of referred to sheets...

Dim SH As Variant
Dim MySheets As Variant
Dim SheetNames As String
' Hard coded list of names
MySheets = Split("ASD,XZC,BNM", ",")
For Each SH In MySheets
With Sheets(SH)
Debug.Print .Cells(1, 1).Value
End With
Next
' Dynamically assigned list of names
SheetNames = "ASD,XZC,BNM,XXX,YYY,ZZZ"
MySheets = Split(SheetNames, ",")
For Each SH In MySheets
With Sheets(SH)
Debug.Print .Cells(1, 1).Value
End With
Next

Notice the list of names in the first argument of the Split function is a
single, comma delimited String (no internal quote marks).

Rick


"Rick Rothstein (MVP - VB)" wrote in
message ...
A structure like this should do what you want; just put your active code
between the With/End With statements using a leading dot for sheet items so
that item will refer to the currently referred to sheet, like my
.Cells(1,1).Value example....

Dim SH As Variant
Dim MySheets As Variant
MySheets = Array("Sheet1", "Sheet4", "Sheet7")
For Each SH In MySheets
With Sheets(SH)
Debug.Print .Cells(1, 1).Value
End With
Next

Rick


"Nabil" wrote in message
...
how can I assign a large number of named sheets to an array variable
(varArray).
In otherwords if I have a collection of large number of named worksheets
like "ASD","XZC","BNM",.......etc.
I want to assign them to the array variable varArray, like;
varArray = "ASD","XZC",......
Then I want to use it in the following statement :
For each asheet in activeworkbook.sheets(varArray)
Please notice that :
-I want to limit the search to limited number of sheets of the
activeworkbook, but the number of these sheets are relatively large (
more
than 20 sheets).
-I want to assign the sheets to the varArray in one seperate line, so
that I
can increase r decrease the number of sheets anytime
-The activeworkbook contains many sheets, but I want to limit the search
(
Done by For ...each )to a certain number out of the total sheet number.
-Are there a limit to the number of sheets used with the statement for...
each?
- I am using Excel 2003 and Excel 2007.
Thank you
--
Nabil A Youssef




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default How do I assign large number of named worksheets to a varArray

Thank you for your help , your code could answer my question. It seems that
you are a proffesional in vba.
Good luck
--
Nabil A Youssef


"Rick Rothstein (MVP - VB)" wrote:

A structure like this should do what you want; just put your active code
between the With/End With statements using a leading dot for sheet items so
that item will refer to the currently referred to sheet, like my
..Cells(1,1).Value example....

Dim SH As Variant
Dim MySheets As Variant
MySheets = Array("Sheet1", "Sheet4", "Sheet7")
For Each SH In MySheets
With Sheets(SH)
Debug.Print .Cells(1, 1).Value
End With
Next

Rick


"Nabil" wrote in message
...
how can I assign a large number of named sheets to an array variable
(varArray).
In otherwords if I have a collection of large number of named worksheets
like "ASD","XZC","BNM",.......etc.
I want to assign them to the array variable varArray, like;
varArray = "ASD","XZC",......
Then I want to use it in the following statement :
For each asheet in activeworkbook.sheets(varArray)
Please notice that :
-I want to limit the search to limited number of sheets of the
activeworkbook, but the number of these sheets are relatively large ( more
than 20 sheets).
-I want to assign the sheets to the varArray in one seperate line, so that
I
can increase r decrease the number of sheets anytime
-The activeworkbook contains many sheets, but I want to limit the search (
Done by For ...each )to a certain number out of the total sheet number.
-Are there a limit to the number of sheets used with the statement for...
each?
- I am using Excel 2003 and Excel 2007.
Thank you
--
Nabil A Youssef



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
Rapidly Create a Large Number of Named Ranges Thomas M. Excel Worksheet Functions 0 May 7th 09 07:09 PM
sum a large number of worksheets Michael Excel Discussion (Misc queries) 5 January 21st 09 05:33 PM
How do i assign the ActiveWorkbook.Worksheets to a worksheets object? TS Excel Programming 0 December 27th 06 02:49 PM
Data sorting over a large number of worksheets xlsuser42 Excel Worksheet Functions 0 August 21st 06 03:20 PM
Assign named ranges Jos Vens Excel Programming 3 July 27th 04 01:48 PM


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