+ Reply to Thread
Results 1 to 6 of 6

Why isn't this code looping through all the sheets?

  1. #1
    Registered User
    Join Date
    01-16-2009
    Location
    Hartford, CT
    MS-Off Ver
    Excel 2010
    Posts
    56

    Why isn't this code looping through all the sheets?

    This code will work on whichever sheet is currently active, but will not continue on to loop through ALL of the sheets. I can't figure out what's wrong. Does something else need to be initialized? Thanks for any suggestions...I'm pulling my hair out!

    Please Login or Register  to view this content.

  2. #2
    Forum Contributor
    Join Date
    02-08-2021
    Location
    africa
    MS-Off Ver
    2016
    Posts
    395

    Re: Why isn't this code looping through all the sheets?

    attach file to help the members
    try this just suggestion
    HTML Code: 

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,575

    Re: Why isn't this code looping through all the sheets?

    You need to qualify the Sheet object to the range
    Please Login or Register  to view this content.
    Otherwise, it always refers to ActiveSheet.Range(....)

  4. #4
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,743

    Re: Why isn't this code looping through all the sheets?

    Quote Originally Posted by MKLAQ View Post
    HTML Code: 
    Sheets.count is more likely for FOR loop. (for i=1 to sheets.count)

    I think:
    Please Login or Register  to view this content.
    as you want to check the same range on all sheets.

    with this:
    Please Login or Register  to view this content.
    My_range is reference into activesheet.
    Happy with my answer * Add Reputation.
    If You are happy with solution, please use Thread tools and mark thread as SOLVED.

  5. #5
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: Why isn't this code looping through all the sheets?

    Try
    Please Login or Register  to view this content.
    A primer on worksheets..
    Last edited by dangelor; 04-07-2021 at 06:41 PM.

  6. #6
    Registered User
    Join Date
    01-16-2009
    Location
    Hartford, CT
    MS-Off Ver
    Excel 2010
    Posts
    56

    Re: Why isn't this code looping through all the sheets?

    Quote Originally Posted by KOKOSEK View Post
    Sheets.count is more likely for FOR loop. (for i=1 to sheets.count)

    I think:
    Please Login or Register  to view this content.
    as you want to check the same range on all sheets.

    with this:
    Please Login or Register  to view this content.
    My_range is reference into activesheet.
    Perfect! My greatest struggle with VBA is understanding initializing and qualifying and when/when not necessary. Thank you so much!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Looping VBA code for Goalseeking skipping certain named sheets
    By Goakseeker in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-05-2020, 06:14 PM
  2. Replies: 1
    Last Post: 10-04-2013, 04:21 AM
  3. [SOLVED] Looping through sheets to clear a specified range, but excluding some sheets
    By d.sanchez in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-03-2013, 02:39 PM
  4. [SOLVED] Looping through sheets help
    By apunc1 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-31-2013, 03:35 PM
  5. [SOLVED] Trying to change verbose looping code into more efficient (and shorter) code please
    By dawatcher in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-03-2013, 07:43 AM
  6. [SOLVED] Looping through sheets to perform code
    By sambuka in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 08-30-2012, 03:25 PM
  7. [SOLVED] Multiple Sheets be reflected in 1 sheets as a summary (looping)
    By Kooper in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-21-2012, 03:21 AM

Tags for this Thread

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