Results 1 to 2 of 2
  1. #1
    3 Star Lounger
    Join Date
    Nov 2001
    Location
    Atlanta, Georgia, USA
    Posts
    274
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Add items to Listbox (Excel2000)

    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?
    <pre>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("ModelDat a").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</pre>



    Thanks,
    Scott

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Add items to Listbox (Excel2000)

    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.

Posting Permissions

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