+ Reply to Thread
Results 1 to 4 of 4

Repeating a loop multiple times

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-19-2009
    Location
    Netherlands, Amsterdam
    MS-Off Ver
    Excel 2010
    Posts
    585

    Repeating a loop multiple times

    Hello all,

    The following code populates a range with values from a listbox.
    The listbox length is variable.
    lets say that the listbox contains for example 25 items.
    The code will fill the range with 25 items.
    How can I keep the loop until it fills the range with for eample 200 items.

    Private Sub CommandButton1_Click()
    For n = 1 To ListBox1.ListCount
        Sheets("ROSTERS").Cells(7, n + 6).Value = ListBox1.List(n - 1)
    Next n
    End Sub

  2. #2
    Valued Forum Contributor Neil_'s Avatar
    Join Date
    04-19-2013
    Location
    Yorkshire
    MS-Off Ver
    Office 365 Enterprise E3 2013 / 2016
    Posts
    479

    Re: Repeating a loop multiple times

    .ListCount informs the loop. If there are 200 items in the list, it will continue until the end of the list. If you change it to
    For n = 1 To 200
    and there aren't 200 items in the list, the code will throw an error
    Frob first, tweak later

  3. #3
    Valued Forum Contributor Neil_'s Avatar
    Join Date
    04-19-2013
    Location
    Yorkshire
    MS-Off Ver
    Office 365 Enterprise E3 2013 / 2016
    Posts
    479

    Re: Repeating a loop multiple times

    i read your post again.

    Private Sub CommandButton1_Click()
    For i = 1 To 200
        n = n +1
        Sheets("ROSTERS").Cells(7, n + 6).Value = ListBox1.List(n - 1)
        If n = ListBox1.ListCount then n = 0
    Next i
    End Sub

  4. #4
    Forum Contributor
    Join Date
    08-19-2009
    Location
    Netherlands, Amsterdam
    MS-Off Ver
    Excel 2010
    Posts
    585

    Re: Repeating a loop multiple times

    Thanks Neil, that worked just great!

+ 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] Repeating the average multiple times
    By dimuthumme in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 02-06-2015, 03:58 PM
  2. [SOLVED] Copy and Paste Multiple times and loop
    By Dnass in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-05-2013, 08:44 PM
  3. Macro to Loop Print 1 Template multiple times
    By run2win17 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-07-2011, 03:29 PM
  4. running loop multiple times?
    By mister tom in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-26-2010, 01:43 PM
  5. Creating a basic loop to solve an equation multiple times
    By MechEng84 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-08-2009, 09:26 PM
  6. Repeating multiple cells a set number of times to print labels
    By Jenrich in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-10-2009, 03:21 PM
  7. VLOOKUP loop multiple times
    By Lenny in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-28-2005, 05:31 AM

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