View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Quick summary of Sheet Names

Doug,

The default method of a collection object is the Item method, so the two
lines of code

Coll("Key")
' and
Coll.Item("Key")

are equivalent. Because I used a With Worksheets statement in the code, I
already have a reference to the Worksheets collection, and therefore use
..Item("Main") to access that particular member of the collection.

used it rather than just Worksheets("MAIN") and Worksheets(Ndx).


Its is because of the With Worksheet statement. I already have a reference
to Worksheets, so all that is necessary to get a member of the collection is
..Item().


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
www.cpearson.com


"Doug Glancy" wrote in message
...
Chip,

I'm very interested in your use of the Item property below. I've never
noticed this property before. I think I see how it allows more

flexibility
in testing for "MAIN" below and then indexing through the sheets, but I'd
love to hear more about how to use this generally, and in this case why

you
used it rather than just Worksheets("MAIN") and Worksheets(Ndx).

Thanks,

Doug

"Chip Pearson" wrote in message
...
Jim,

Try the following:

Sub AAA()
Dim WS As Worksheet
Dim Ndx As Long
On Error Resume Next
With Worksheets
Set WS = .Item("MAIN")
If Err.Number < 0 Then
Set WS = .Add
WS.Name = "MAIN"
End If
For Ndx = 1 To .Count
.Item("MAIN").Cells(Ndx, 1).Value = .Item(Ndx).Name
Next Ndx
End With
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
www.cpearson.com


"Jim May" wrote in message
...
I have inherited a single Workbook with 125 Tabs
(Worksheets). I'd like to code a macro to "dump" all
sheets names to a newly created worksheet named "Main"
(which I've inserted in the 1st position). The worksheet
names should appear in Main in the Cells A1:A125. How can
I do this?