Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Activating all sheets in turn in an Excel workbook

Status
Not open for further replies.

tom1681

Programmer
Sep 4, 2002
40
GB
I'm trying to get a VBA script to enter data in certain cells on every sheet in an Excel XP (2002) workbook. This script will be used in several workbooks all of which have a different number of sheets with different names. I can get the number of sheets by using Worksheets.Count, but can't activate each one in turn as I can't use a variable in the (sheet name).Activate command.
Does any one have any ideas as to a possible solution?

TIA.

---
Tom
 
Use the sheet index number or the worksheets collection

Sub UseCollectionObjects()
For Each ws in activeworkbook.worksheets
ws.range("A1").value = ws.name
next
end sub

Sub IterateThruIndex()
For i = 1 to activeworkbook.worksheeets.count
sheets(i).range("A1").value = sheets(i).name
next i
end sub

HTH
Rgds
~Geoff~
 
Lovely! That second one is just what I wanted.

Ta.


---
Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top