+ Reply to Thread
Results 1 to 4 of 4

use the same variable again in loop

  1. #1
    Registered User
    Join Date
    01-30-2020
    Location
    UK
    MS-Off Ver
    2013
    Posts
    82

    use the same variable again in loop

    Hi there,

    I'm trying to "re-use" an array to create different outputs with the same sub, but I'm not sure if I can re-use the same variables of 'i' and 'o'. My code tells me that NextRow: is a duplicate declaration too.

    Is there a way to achieve this or do I need to use fresh variables?

    Cheers!
    Last edited by warp765; 05-23-2020 at 02:19 PM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,093

    Re: use the same variable again in loop

    NextRow: is a label and it is indeed declared/used twice. If you want to use GoTo (albeit frowned upon), you should maybe use NextRow1: and NextRow2:

    No reason why you can't re-use your variables as long as they are initialised, or are in a from-to structure, and the loops don't overlap.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    01-30-2020
    Location
    UK
    MS-Off Ver
    2013
    Posts
    82

    Re: use the same variable again in loop

    TMS, brilliant thank you!

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,093

    Re: use the same variable again in loop

    You're welcome. Thanks for the rep.

+ 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] Error handling not working in "vba object variable or with block variable not set" in Loop
    By caabdul in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-23-2019, 06:40 PM
  2. [SOLVED] Can i make the column I want to loop a variable? (i,VARIABLE) instead of (i,2)
    By trenzalore888 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-31-2017, 12:48 PM
  3. [SOLVED] correctly 'wording' a for/next loop using a variable counter and variable filter
    By DBoyd121 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-14-2016, 06:13 PM
  4. [SOLVED] VB Loop different variables and stop variable to find a new variable..
    By feroguz in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-14-2014, 04:54 PM
  5. Replies: 6
    Last Post: 12-21-2012, 08:03 AM
  6. Why did an inner loop variable start overwriting the outer loop range suddenly?
    By 111StepsAhead in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-16-2012, 03:24 PM
  7. [SOLVED] For Each ... Next loop - need to reference the loop variable
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-13-2006, 01:15 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