PDA

View Full Version : Solved: Cycle trhough worksheets



troelsi
12-18-2008, 12:23 AM
Dear experts!

I know this a simple question, but I just couldn't find the information elsewhere, sorry.

How do I cycle or loop through each worksheet in a workbook?

Thanks in advance

Regards

troels

JimmyTheHand
12-18-2008, 12:33 AM
Dim WS As Worksheet, WB As Workbook
Set WB = ThisWorkbook

For Each WS In WB.Worksheets
'here comes the code of what you want to do with the current worksheet
Next

troelsi
12-18-2008, 01:28 AM
Great thanks a lot.

Suppose I want to store or print each name of the worksheets I cycle through, how do I do that?

Bob Phillips
12-18-2008, 02:18 AM
Dim WS As Worksheet, WB As Workbook
Dim i As Long
Set WB = ThisWorkbook

For Each WS In WB.Worksheets

i = i + 1
Cells(i, "A").Value = WS.Name
Next

troelsi
12-18-2008, 02:46 AM
Perfect! thanks!