I have some employee Names on column "A" and relevant employee Numbers on column "B" in sheet1. On userform I have a combobox that shows employee names,i want when a name is selected on combobox his/her employee Number shown on a nearby txtbox.
I know a codeI've put it in Userform module But it gives Compile error "Variable not defined" on this lineCode:Option Explicit Private Sub cboNames_Change() txtEmployeeNumber.Value = Worksheets("Sheet4").Cells(cboNames.ListIndex + 1, 2) End Sub '========================================================================= Private Sub UserForm_Initialize() Dim LastRow As Long cboNames.Clear With Worksheets("Sheet4") '<--replace "Sheet4" with the sheet you have your employees data LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row cboNames.List = Application.Transpose(.Range("A2:A" & LastRow).Value) End With End Sub
Code:txtEmployeeNumber.Value = Worksheets("Sheet4").Cells(cboNames.ListIndex + 1, 2)




Reply With Quote
