Vishwanath Korgaonkar
New Member
- Joined
- Sep 16, 2021
- Messages
- 15
- Office Version
- 365
- Platform
- Windows
H
I have two combobox one for emp Id(combobox12) and one for emp name(combobox13).The values are added in combobox with change event of combobox1. if I select name from combobox13 the it display corresponding Emp id in combobox12 my code is as follows
Private Sub ComboBox13_Change()
Dim i As Long, lastrow As Long
Dim sh As Worksheet
With ActiveWorkbook.Sheets("Other_Details")
Set sh = ActiveWorkbook.Sheets("Other_Details")
lastrow = sh.Range("AH" & Rows.Count).End(xlUp).Row
For i = 4 To lastrow
If sh.Cells(i, "AH").Value = Me.ComboBox13.Value Then
Me.ComboBox12.Value = sh.Cells(i, "AG").Value
End If
Next
End With
End Sub
But if I use the code other way round it does not work.for example if I select the employee ID it does not display employee name nor it gives any error my code is as follows
Private Sub ComboBox12_Change()
Dim i As Long, lastrow As Long
Dim sh As Worksheet
With ActiveWorkbook.Sheets("Other_Details")
Set sh = ActiveWorkbook.Sheets("Other_Details")
lastrow = sh.Range("AG" & Rows.Count).End(xlUp).Row
For i = 4 To lastrow
If sh.Cells(i, "AG").Value = Me.ComboBox12.Value Then
Me.ComboBox13.Value = sh.Cells(i, "AH").Value
End If
Next
End With
the data range is in whorksheet "Other_Details" cells AG:AH
My same logic works for 2 others comboxes in same userform but I cannot figure out what is gone wrong?
can any one help?
I have two combobox one for emp Id(combobox12) and one for emp name(combobox13).The values are added in combobox with change event of combobox1. if I select name from combobox13 the it display corresponding Emp id in combobox12 my code is as follows
Private Sub ComboBox13_Change()
Dim i As Long, lastrow As Long
Dim sh As Worksheet
With ActiveWorkbook.Sheets("Other_Details")
Set sh = ActiveWorkbook.Sheets("Other_Details")
lastrow = sh.Range("AH" & Rows.Count).End(xlUp).Row
For i = 4 To lastrow
If sh.Cells(i, "AH").Value = Me.ComboBox13.Value Then
Me.ComboBox12.Value = sh.Cells(i, "AG").Value
End If
Next
End With
End Sub
But if I use the code other way round it does not work.for example if I select the employee ID it does not display employee name nor it gives any error my code is as follows
Private Sub ComboBox12_Change()
Dim i As Long, lastrow As Long
Dim sh As Worksheet
With ActiveWorkbook.Sheets("Other_Details")
Set sh = ActiveWorkbook.Sheets("Other_Details")
lastrow = sh.Range("AG" & Rows.Count).End(xlUp).Row
For i = 4 To lastrow
If sh.Cells(i, "AG").Value = Me.ComboBox12.Value Then
Me.ComboBox13.Value = sh.Cells(i, "AH").Value
End If
Next
End With
the data range is in whorksheet "Other_Details" cells AG:AH
My same logic works for 2 others comboxes in same userform but I cannot figure out what is gone wrong?
can any one help?