Hi guys
I have been trying to populate a listbox using option buttons then click on the listbox to do a vlookup and populate 4 textboxes. When I open the userform and click on any of the option buttons the listbox populates correctly and so do the textboxes when I click on the listbox item, however when I click on another option button I get an error. First thought was to clear the listbox but this also creates an error.
The option buttons represent 11 different worksheets and the listbox are names taken from those sheets, then use the name to populate the textboxes with info from vlookup.
Private Sub optBowser_Change()
Dim rng As Range
Dim LastRow As Long
With Sheets("Bowser")
LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
Set rng = .Range(.Cells(4, 1), .Cells(LastRow, 1))
End With
frmAnnualLeave.lstNames.Clear
With Me.lstNames
.RowSource = rng.Address(external:=True)
End With
End Sub
Private Sub lstNames_Click()
If optBowser.Value = True Then
txtEntitlement.Value = Application.WorksheetFunction.VLookup(Me.lstNames.Value, Sheets("Bowser").Range("A4:E8"), 2, False)
txtAvailable.Value = Application.WorksheetFunction.VLookup(Me.lstNames.Value, Sheets("Bowser").Range("A4:E8"), 3, False)
txtSick.Value = Application.WorksheetFunction.VLookup(Me.lstNames.Value, Sheets("Bowser").Range("A4:E8"), 4, False)
txtFTJ.Value = Application.WorksheetFunction.VLookup(Me.lstNames.Value, Sheets("Bowser").Range("A4:E8"), 5, False)
End If
End Sub
Hope you can understand where Im going with this and any help would be appreciated.
wingnut74
Moderator's note: I have added code tags because it's your first post. Please take the time to review our rules. There aren't many, and they are all important. --6StringJazzer
Bookmarks