0

I have a userform with a Listbox. I want to add items to it using List.

I get a syntax error when it comes to the List function. I can't get the property List.

Private Sub UserForm_Initialize()
    Dim lRow As Long
    Dim i As Long

    With Me.lsbVarden
        .Clear
        .ColumnHeads = False
        .ColumnCount = 3
        .ColumnWidths = "70;70;10"

        lRow = Cells(Rows.count, 1).End(xlUp).Row
    
        For i = 1 To lRow
            .AddItem
            .List(i, 0) = Cells(i, 2).Value
            .List(i, 1) = Cells(i, 3).Value
            .List(i, 2) = Cells(i, 3).Row       
        Next i

        .MultiSelect = fmMultiSelectExtended
    End With

End Sub
Anatoly
  • 20,799
  • 3
  • 28
  • 42
Mirkaminer
  • 79
  • 8
  • 1
    `.AddItem Cells(i, 2).Value` and THEN use `.List` to add the rest – braX Oct 28 '20 at 10:25
  • 3
    Indexing starts at 0, so you should be using `.List(i - 1, 0)` etc – Rory Oct 28 '20 at 10:26
  • Adding the ```.List(i - 1, 0)``` to the function fixted the error. Thank you. – Mirkaminer Oct 28 '20 at 11:11
  • 1
    @Mirkaminer - FYI might have a look at [Populate listbox with multiple columns](https://stackoverflow.com/questions/47528558/vba-excel-populate-listbox-with-multiple-columns/47531440#47531440) explaining the *array* method. – T.M. Dec 11 '20 at 13:14

0 Answers0