+ Reply to Thread
Results 1 to 2 of 2

Multiple Listbox? Population

  1. #1
    Pete
    Guest

    Multiple Listbox? Population

    I have 32 list boxes on a userform. I want to populate them with the same
    data. The list boxes are named listbox1, listbox2, etc.

    Is there an easier way to populate these boxes instead of doing each one
    separately?

    Like a loop or something

    Dim Counter, Listboxnumber AS Single
    For Counter = 1 to 50
    For lbnbr = 1 to 32
    Listbox & Listboxnumber.additem Counter
    Next Listboxnumber
    Next Counter


  2. #2
    keepITcool
    Guest

    Re: Multiple Listbox? Population

    Private Sub UserForm_Initialize()

    Dim i As Integer
    Dim aItems() As String
    Const nItems As Integer = 50
    Const nLists As Integer = 32

    'Create a 0based, 2 Dimensional array for the listitems
    ReDim aItems(0 To nItems - 1, 0 To 0)
    'Fill it...
    For i = 1 To nItems
    aItems(i - 1, 0) = "Item" & i
    Next

    'Assign the array to each control's list property
    For i = 1 To nLists
    Me.Controls("Listbox" & i).List = aItems
    Next


    End Sub




    --
    keepITcool
    | www.XLsupport.com | keepITcool chello nl | amsterdam


    Pete wrote :

    > I have 32 list boxes on a userform. I want to populate them with the
    > same data. The list boxes are named listbox1, listbox2, etc.
    >
    > Is there an easier way to populate these boxes instead of doing each
    > one separately?
    >
    > Like a loop or something
    >
    > Dim Counter, Listboxnumber AS Single
    > For Counter = 1 to 50
    > For lbnbr = 1 to 32
    > Listbox & Listboxnumber.additem Counter
    > Next Listboxnumber
    > Next Counter


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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