Good Morning All!
I am loading a userform that gets populated with a number of fields from a table depending on the currently selected row.
I would like to use a listbox in the userform to give the user options to change a cell in that row. Effectively using a flat database and a basic front end to edit the data.
I am struggling to get the listbox to be pre-selected with a value.
I am populating the listbox with a dynamic named range to enable more options to be added in the future.
Dim rRange As Range
Dim rCell As Range
Dim lCount As Long
Set rRange = Range("STATUStbl")
For Each rCell In rRange
ListBox1.AddItem rCell.Value
Next
the above code successfully populates the listbox, the below code doesn't successfully autoselect the value in column 2 of the table!
With ListBox1
For lCount = 0 To .ListCount - 1
If (.Column(2, lCount)) = Cells(ActiveWindow.RangeSelection.Row, 2) Then
.Selected(lCount) = True
Else
.Selected(lCount) = False
End If
Next
End With
Please see attached, and please help!
Bookmarks