+ Reply to Thread
Results 1 to 2 of 2

Variable for loop

  1. #1
    Registered User
    Join Date
    10-17-2020
    Location
    Boise, Idaho
    MS-Off Ver
    16
    Posts
    5

    Variable for loop

    Hey everyone,
    What I’d like to know is is it possible to do a variable for loop where you can tell it to do the loop so many times. For example I am doing this to keep track of my team stats but the number of people on my team is variable and changes on a irregular basis and so it is difficult to constantly have to remove or add people here and then modify my macro to fit my new team size

    Sub test ()

    Dim a as integer, I as integer
    a = range(“b2”)

    For i = 1 to a
    Activecell.value = inputbox(“how many surveys?”)
    Activecell.offset(1,0).activate
    Next i

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Variable for loop

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)


    Also:

    Please post a sample workbook
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

+ 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