View Full Version : Solved: worksheet counting
ProteanBeing
11-27-2007, 11:44 AM
How do I identify the position of a worksheet using the sheet name?
Example: The sheet tab is named Blank. I want to loop from blank to the last tab in the workbook using a for next loop.
Bob Phillips
11-27-2007, 11:47 AM
Sub LoopSheets()
Dim idx As Long
For idx = Worksheets("blank").Index To Worksheets.Count
'do stuff
Next idx
End Sub
ProteanBeing
11-27-2007, 11:51 AM
Thanks!! That helped a lot!!
Just be aware that the Index property of the worksheet returns its index number in the Sheets collection, not the Worksheets collection, and if you have Chart sheets, this may cause you problems. For example, if you workbook contained a chart sheet and a worksheet called Sheet1 (in that order), this would actually error:
MsgBox Worksheets(Worksheets("Sheet1").index).name
rather than displaying "Sheet1" in a messagebox. So you need to use:
MsgBox Sheets(Worksheets("Sheet1").index).name
FWIW.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.