+ Reply to Thread
Results 1 to 4 of 4

VBA Loop not looping

  1. #1
    Registered User
    Join Date
    04-18-2011
    Location
    Milwaukee, WI
    MS-Off Ver
    Excel 2003
    Posts
    7

    VBA Loop not looping

    I am having a problem with my code not looping through any sheets. I used case to exclude a couple of the sheets from hardcoding. It runs through the code and just keeps pasting on the same sheet over and over without moving to any other sheets. Anyone got any idea why this is happening. Thanks.
    Please Login or Register  to view this content.

  2. #2
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: VBA Loop not looping

    Insert:
    Please Login or Register  to view this content.
    immediately after the For statement
    Gary's Student

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,236

    Re: VBA Loop not looping

    Hi,

    When you do a "Range( ).Select" it works on the active sheet (the one you are viewing). You will either need to Select your different sheets in the code or do a With Worksheets( ) type of statement in your code to get data from different sheets.

    Look at http://www.ozgrid.com/VBA/sheet-index.htm for the example.

    Note - when using the WITH Worksheets type of code ".Range" is dealing on the WITH sheet and "Range" is dealing with the current/viewed sheet.
    This period in front of Range or Cell is such a small dot but it has such GREAT meaning.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Registered User
    Join Date
    04-18-2011
    Location
    Milwaukee, WI
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: VBA Loop not looping

    Thank you both for the explanation and the fix. Much Appreciated.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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