+ Reply to Thread
Results 1 to 5 of 5

Issue with loop

  1. #1
    Registered User
    Join Date
    06-03-2014
    MS-Off Ver
    2007
    Posts
    87

    Issue with loop

    Hi,

    I have an issue with my loop. It doesn't loop through the sheets and stays on the activesheet. I think the problem is coming from the code I have highlighted in red. However, I'm short on ideas on how to correct the situation.

    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor Miraun's Avatar
    Join Date
    04-03-2009
    Location
    New England
    MS-Off Ver
    2003, 2007, 2010, 2013
    Posts
    554

    Re: Issue with loop

    You need to add in a
    WS.Activate
    before the rng = activesheet.usedrange

    Or potentially change it to ws.usedranged... but not sure offhand
    Going for Guru! Click the Star to the bottom left of this post if I helped!

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Issue with loop

    Please Login or Register  to view this content.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Issue with loop

    No need to use ActiveSheet or Activate, you just need to tell VBA which sheet you want the UsedRange of.

    In this case that's the current worksheet in the loop, ws.
    Please Login or Register  to view this content.
    PS Be careful where you use On Error Resume Next, in this code I wouldn't use it's probably not needed anywhere
    If posting code please use code tags, see here.

  5. #5
    Registered User
    Join Date
    06-03-2014
    MS-Off Ver
    2007
    Posts
    87

    Re: Issue with loop

    AB33 & Norie, your ideas are the same but have a different formulation.

    Thank you, it both worked.

+ 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. Loop issue
    By jsmilke in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-06-2014, 01:44 AM
  2. For...Next Loop issue
    By FK7Design in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-20-2010, 10:12 AM
  3. For Loop Issue
    By pr4t3ek in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-12-2008, 10:40 AM
  4. For each loop issue
    By goofy78270 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-19-2007, 07:22 PM
  5. [SOLVED] Issue with Do Loop
    By Linking to specific cells in pivot table in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-24-2005, 06:05 PM

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