• Add items to Listbox (Excel2000)

    Author
    Topic
    #441854

    I’m using this code to populate a listbox with data from another sheet.
    Is there a way to add a button the the form to let the user add an item that isn’t in the list?

    Function UserForm1_Initialize()
        Dim lbtarget As MSForms.ListBox
        Dim rngSource As Range
        
        'Set reference to the range of data to be filled
        Set rngSource = Worksheets("ModelData").Range(Worksheets("ModelData").Range("A1"), _
        Worksheets("ModelData").Range("D1").End(xlDown))
      
        'Fill the listbox
        Set lbtarget = UserForm1.ListBox1
        With lbtarget
            'Determine number of columns
            .ColumnCount = 4
            'Set column widths
            .ColumnWidths = "45;60;60;50"
            'Insert the range of data supplied
            .List = rngSource.Cells.Value
        End With
        '   Show the UserForm
        UserForm1.Show
    End Function

    Thanks,
    Scott

    Viewing 0 reply threads
    Author
    Replies
    • #1061929

      You’d have to let the user provide 4 values, since your list box has 4 columns, then enter these values in the first empty row below the current data in the ModelData sheet, and set the List property of the list box again. Or use the AddItem method to add the item for the first column, then use Column to set the other three columns.

    Viewing 0 reply threads
    Reply To: Add items to Listbox (Excel2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: