+ Reply to Thread
Results 1 to 5 of 5

loop through alternate worksheets in the workbook

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-30-2012
    Location
    australia
    MS-Off Ver
    Excel 2003
    Posts
    118

    loop through alternate worksheets in the workbook

    Hello

    If someone could help me with the following criteria:

    I have many worksheets(about 22), I want to loop and select every 1st, 3rd,5th,7th....... and so on till the end. can i get the code of how to go abt it,

    the below code just goes through each worksheets


    For Each ws In ActiveWorkbook.Worksheets
    ;;;;
    Next ws
    Last edited by irfanparbatani; 08-22-2012 at 02:06 AM.

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: loop through alternate file in the workbook

    Hi, irfanparbatani,

    maybe use the index of the worksheets if there´s no other criteria
    Dim lngCounter As Long
    For lngCounter = 1 To ActiveWorkbook.Worksheets.Count Step 2
      With Worksheets(lngCounter)
        'your code
      End With
    Next lngCounter
    Ciao,
    Holger
    Last edited by HaHoBe; 08-22-2012 at 02:22 AM. Reason: amended the With-Part in the code, thanks arlu for the hint

  3. #3
    Forum Contributor
    Join Date
    07-30-2012
    Location
    australia
    MS-Off Ver
    Excel 2003
    Posts
    118

    Re: loop through alternate file in the workbook

    gives error argument not option before executing step 2.

    ---------- Post added at 04:25 PM ---------- Previous post was at 04:22 PM ----------

    Thanks arlu, for you help bro.

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: loop through alternate worksheets in the workbook

    Try this

    Dim i As Long
    
    For i = 1 To Worksheets.Count Step 2
        'Your code here
    Next i
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  5. #5
    Forum Contributor
    Join Date
    07-30-2012
    Location
    australia
    MS-Off Ver
    Excel 2003
    Posts
    118

    Re: loop through alternate worksheets in the workbook

    Quote Originally Posted by arlu1201 View Post
    Try this

    Dim i As Long
    
    For i = 1 To Worksheets.Count Step 2
        'Your code here
    Next i

    Can we stop looping the macro with the name sheet , cuz I do not want to continue beyond that point.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1