Results 1 to 7 of 7
  1. #1
    4 Star Lounger
    Join Date
    May 2004
    Location
    Toronto, Ontario, Canada
    Posts
    425
    Thanks
    5
    Thanked 0 Times in 0 Posts

    LOOP Counter (Excel 2000)

    Hi all,

    I'm out of the Loop<img src=/S/smile.gif border=0 alt=smile width=15 height=15>
    I want to create a loop for a listbox.list that is 1 to 1000, I think I have the right loop with For Next, and Counter but I am not sure.

    Sub goforaloop()
    Dim I as long
    I = 2
    For I =1 to 1000
    Next
    ListBox1.list = I
    End sub

    What I have now doesn't work. <img src=/S/blackteeth.gif border=0 alt=blackteeth width=20 height=20>

    Thanks, Darryl.

  2. #2
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Vienna, Wien, Austria
    Posts
    5,009
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: LOOP Counter (Excel 2000)

    <P ID="edit" class=small>(Edited by unkamunka on 13-Nov-04 15:54. )</P>Try

    Sub goforaloop()
    Dim I as long
    I = 2
    For I =1 to 1000
    <font color=red>ListBox1.list = I
    I=I+1
    Next I</font color=red>
    End sub

    Is there a particular reason why you're starting the loop with I set to 2 (and not 1)?
    Gre

  3. #3
    4 Star Lounger
    Join Date
    May 2004
    Location
    Toronto, Ontario, Canada
    Posts
    425
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Re: LOOP Counter (Excel 2000)

    Yes, I want it to count by 2's

  4. #4
    4 Star Lounger
    Join Date
    May 2004
    Location
    Toronto, Ontario, Canada
    Posts
    425
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Re: LOOP Counter (Excel 2000)

    OK...thanks,

    But it doesn't work for me.....the list in the listbox is blank.

  5. #5
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Vienna, Wien, Austria
    Posts
    5,009
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: LOOP Counter (Excel 2000)

    <P ID="edit" class=small>(Edited by unkamunka on 13-Nov-04 17:11. )</P>Then try


    Sub goforaloop()
    Dim I As Long
    I = 2
    For I = <font color=red>2 To 1000 Step 2
    ListBox1.list = I
    Next I</font color=red>
    End Sub
    Gre

  6. #6
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Vienna, Wien, Austria
    Posts
    5,009
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: LOOP Counter (Excel 2000)

    Is this what you're looking for

    Private Sub ListBox1_Click()
    Dim I As Long
    I = 2
    For I = 2 To 1000 Step 2
    ListBox1.AddItem I
    Next I
    End Sub

    You need to add this to the Code section of whatever Worksheet that the ListBox has been placed on. You also need to be using a ListBox from the Control Toolbox toolbar.

    HTH
    Gre

  7. #7
    4 Star Lounger
    Join Date
    May 2004
    Location
    Toronto, Ontario, Canada
    Posts
    425
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Re: LOOP Counter (Excel 2000)

    Thank you works great

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •