Consulting

Results 1 to 3 of 3

Thread: Populate list box from another sheet

  1. #1

    Populate list box from another sheet

    I have a workbook with 8 sheets in.

    the first 7 are days in the week. The 8th has some reference data.

    I would like to create a user form for populating data into the weekdays sheets.

    I would like to put on this form a list box that only allows certain data to be entered. The criteria for that data is on sheet 8 column 'A'

    How do I link the listbox1 to the information on page 8.



    Regards

  2. #2
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    Here's a possible method...

    Set a name the range you want to use (e.g. "MachineNames")
    In the user form initialize event:
    Declare a variant
    Assign the named range array to the variant
    Assign the variant to the Listbox's List property
    [VBA]Dim varMachineNames

    varMachineNames = Sheets(8).Range("MachineNames")
    ListBox1.List() = varMachineNames
    ListBox1.ListIndex = 0[/VBA]
    K :-)

  3. #3
    Administrator
    Chat VP
    VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Without using range names...[vba]Option Explicit

    Private Sub UserForm_Activate()
    Dim M As Long
    With Sheet6
    For M = 1 To .Range("A" & Rows.Count).End(xlUp).Row
    ListBox1.AddItem .Range("A" & M)
    Next M
    End With
    End Sub[/vba]{The eighth sheet in your example has the code name Sheet6)}
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

Posting Permissions

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