Consulting

Results 1 to 5 of 5

Thread: Solved: Cycle trhough worksheets

  1. #1
    VBAX Regular
    Joined
    Sep 2006
    Posts
    65
    Location

    Solved: Cycle trhough worksheets

    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

  2. #2
    [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.

  3. #3
    VBAX Regular
    Joined
    Sep 2006
    Posts
    65
    Location
    Great thanks a lot.

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

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [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

  5. #5
    VBAX Regular
    Joined
    Sep 2006
    Posts
    65
    Location
    Perfect! thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •