Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 553
Default Loading Sheets into a Customer Collection

I have a custom collection called Myworksheets. I want to load a certain
sheets into this collection. The syntax below works. I have two questions:

1) Can someone explain the syntax to me. Not sure what the difference is
between the sheet name in the bracket and the sheet name outside the bracket.

2) This assumes I know the names of the sheets. What if the sheet names
were loaded into a listbox. How would I adjust the code to loop through the
list box and load the sheets into my custom collection.

With MyWorksheets
.Add ThisWorkbook.Worksheets("Sheet1"), "Sheet1"
.Add ThisWorkbook.Worksheets("Sheet4"), "Sheet4"
End With

Thanks

EM
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 421
Default Loading Sheets into a Customer Collection

Hi Excel Monkey,

The instruction:

.Add ThisWorkbook.Worksheets("Sheet1"), "Sheet1"

is an abbreviated form of:

myColl.Add Item:=ThisWorkbook.Worksheets("Sheet1"), _
Key:="Sheet1"

This loads the worksheet into the collection,
as an object (a worksheet) and uses the
worksheet's name as the Collection's key.

To load the load the Collection with the
contents of a ListBox, try something like:
'===========
Private Sub CommandButton1_Click()
Dim i As Long
Dim myColl As Collection

Set myColl = New Collection

On Error Resume Next
With Me.ListBox1
For i = 1 To .ListCount
myColl.Add item:=.List(i), Key:=CStr(.List(i))
Next i
On Error GoTo 0
End With
End Sub
'<<===========




---
Regards.
Norman


"ExcelMonkey" wrote in message
...
I have a custom collection called Myworksheets. I want to load a certain
sheets into this collection. The syntax below works. I have two
questions:

1) Can someone explain the syntax to me. Not sure what the difference is
between the sheet name in the bracket and the sheet name outside the
bracket.

2) This assumes I know the names of the sheets. What if the sheet names
were loaded into a listbox. How would I adjust the code to loop through
the
list box and load the sheets into my custom collection.

With MyWorksheets
.Add ThisWorkbook.Worksheets("Sheet1"), "Sheet1"
.Add ThisWorkbook.Worksheets("Sheet4"), "Sheet4"
End With

Thanks

EM


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 553
Default Loading Sheets into a Customer Collection

That's helpful. Thank-you.

EM

"Norman Jones" wrote:

Hi Excel Monkey,

The instruction:

.Add ThisWorkbook.Worksheets("Sheet1"), "Sheet1"

is an abbreviated form of:

myColl.Add Item:=ThisWorkbook.Worksheets("Sheet1"), _
Key:="Sheet1"

This loads the worksheet into the collection,
as an object (a worksheet) and uses the
worksheet's name as the Collection's key.

To load the load the Collection with the
contents of a ListBox, try something like:
'===========
Private Sub CommandButton1_Click()
Dim i As Long
Dim myColl As Collection

Set myColl = New Collection

On Error Resume Next
With Me.ListBox1
For i = 1 To .ListCount
myColl.Add item:=.List(i), Key:=CStr(.List(i))
Next i
On Error GoTo 0
End With
End Sub
'<<===========




---
Regards.
Norman


"ExcelMonkey" wrote in message
...
I have a custom collection called Myworksheets. I want to load a certain
sheets into this collection. The syntax below works. I have two
questions:

1) Can someone explain the syntax to me. Not sure what the difference is
between the sheet name in the bracket and the sheet name outside the
bracket.

2) This assumes I know the names of the sheets. What if the sheet names
were loaded into a listbox. How would I adjust the code to loop through
the
list box and load the sheets into my custom collection.

With MyWorksheets
.Add ThisWorkbook.Worksheets("Sheet1"), "Sheet1"
.Add ThisWorkbook.Worksheets("Sheet4"), "Sheet4"
End With

Thanks

EM


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
column widths change when loading customer Excel files crdman1 Excel Discussion (Misc queries) 0 April 20th 09 07:42 PM
customer style across sheets BorisS Excel Discussion (Misc queries) 0 March 12th 08 01:44 PM
CONVER CSV CUSTOMER DATA TO A CUSTOM INDIVI CUSTOMER PRICE SHEET brunod Excel Discussion (Misc queries) 1 July 7th 06 07:01 PM
creating a collection of Sheets references Eric[_27_] Excel Programming 1 February 6th 05 01:20 PM
collection of sheets mark Excel Programming 6 February 2nd 05 11:38 PM


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