+ Reply to Thread
Results 1 to 4 of 4

How to loop through as many times as userform answer

Hybrid View

  1. #1
    Registered User
    Join Date
    02-20-2014
    Location
    LA
    MS-Off Ver
    Excel 2013
    Posts
    27

    How to loop through as many times as userform answer

    Hello,

    I hope I can explain this well...I have a user form pop up when a macro is run, and it prompts to put in a number. Depending on that number (x), a macro is re-interated "x" number of times. So far, all I can think of is to write "x" versions of that macro, so if the 2 was entered, then the "2" version of that macro would be run. I would just like it to loop as many times as the userform answer.

    I feel like there already exists an answer to this, as it seems like something that is used often, but I couldn't find anything. Any help is much appreciated.

    Many thanks!

  2. #2
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: How to loop through as many times as userform answer

    dim x&
    
    Do while x < 10 'instead of 10, put the userform input here
    
    'your code
    
    x = x + 1
    Loop
    Please click the * below if this helps

  3. #3
    Registered User
    Join Date
    02-20-2014
    Location
    LA
    MS-Off Ver
    Excel 2013
    Posts
    27

    Re: How to loop through as many times as userform answer

    Hi,

    Thanks for the info! With some messing around with what you provided, I came up with a slightly different method which worked for my purposes:

    Dim i As Integer
    Dim x&
    x = UserForm1.TextBox1.Value
    For i = 1 To x
    
    'code stuffs
    
    Next

  4. #4
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: How to loop through as many times as userform answer

    Great to hear you found your solution.
    Just for future reference, you don't need the i in your code.
    dim x&
    
    Do while x < UserForm1.TextBox1.Value
    
    'your code
    
    x = x + 1
    Loop
    Also, the & in the dim is an abbreviation - see all abbreviations below:
    integer : % (so you could have said dim i%)
    long : &
    single : !
    double : #
    string : $
    currency : @

+ 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. HOW TO: Pause loop, fix error on a popup UserForm, continue loop
    By AndyMachin in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-19-2014, 04:37 PM
  2. [SOLVED] Counting the number of times an answer appears in a column
    By JennOlsen in forum Excel Charting & Pivots
    Replies: 7
    Last Post: 01-09-2014, 05:19 PM
  3. Need a formula to answer how many times a value changes within an array
    By agf12555 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-19-2012, 11:00 AM
  4. Macro Loop – Find Specific Times, Extract Date, Average Values of Times
    By ExcelQuestFL in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 02-25-2010, 02:50 PM
  5. [SOLVED] How do I add up a range of times giving answer in hrs & mins >24h.
    By Richard T in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-13-2005, 12:06 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