+ Reply to Thread
Results 1 to 6 of 6

Excel won't loop through worksheets

  1. #1
    Registered User
    Join Date
    07-06-2012
    Location
    nh
    MS-Off Ver
    Excel 2003
    Posts
    36

    Excel won't loop through worksheets

    I am trying to loop through all my work sheets and apply this code however it’s not looping through, it’s only working on the current sheet that’s open. Hoping someone here can help me out. Thank you.

    Formula: copy to clipboard
    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    917

    Re: Excel won't loop through worksheets

    You need to activate the next sheet so add at least this row to your script:
    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Excel won't loop through worksheets

    audioboxer,

    When posting VBA code, please use Code Tags - like this:

    [code]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/code]


    Your code is only running on the active worksheet.

    And, you do not have to activate a sheet, in order for the code to work correctly.

    Please replace your posted code with the below code. If it does not work correctly, then please attach your workbook.


    Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

    Please Login or Register  to view this content.
    Have a great day,
    Stan

    Windows 10, Excel 2007, on a PC.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  4. #4
    Registered User
    Join Date
    07-06-2012
    Location
    nh
    MS-Off Ver
    Excel 2003
    Posts
    36

    Re: Excel won't loop through worksheets

    Quote Originally Posted by rollis13 View Post
    You need to activate the next sheet so add at least this row to your script:
    Please Login or Register  to view this content.
    Thanks for your help. Worked perfect.

  5. #5
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    917

    Re: Excel won't loop through worksheets

    Glad being of some help , but as said by stanleydgromjr, you do not need to activate or select the sheet if you change all your script as suggested.

  6. #6
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Excel won't loop through worksheets

    rollis13,

    Thank you very much.

    And, the code will execute faster because you do not have to Activate/Select a worksheet.

+ 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