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
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
[vba]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[/vba]
-------------------------------------------------
The more details you give, the easier it is to understand your question. Don't save the effort, tell us twice rather than not at all. The amount of info you give strongly influences the quality of answer, and also how fast you get it.
Great thanks a lot.
Suppose I want to store or print each name of the worksheets I cycle through, how do I do that?
[vba]
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
[/vba]
____________________________________________
Nihil simul inventum est et perfectum
Abusus non tollit usum
Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
James Thurber
Perfect! thanks!