Xin chào mng,
Em có 1 vấn đề sau mong mng giúp đỡ :
- Em muốn khi mình chọn giá trị ở cột First Name (trong Userform1) thì tự động Last Name sẽ nhận giá trị ở cột tương ứng.
Đây là đoạn Code :
Private Sub ComboBox1_Change()
Dim i As Long
Dim lastrow As Long
Dim ws As Worksheet
Set ws = Sheets("Sheet1")
lastrow = ws.Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To lastrow
If Val(Me.ComboBox1.Value) = ws.Cells(i, "A") Then
Me.TextBox1.Value = ws.Cells(i, "B").Value
End If
Next i
End Sub
Em cảm ơn
![1533225924859.png 1533225924859.png](https://www.giaiphapexcel.com/diendan/data/attachments/158/158049-2b52923b229dfcad06496de84f6bf8a8.jpg?hash=K1KSOyKd_K)
Em có 1 vấn đề sau mong mng giúp đỡ :
- Em muốn khi mình chọn giá trị ở cột First Name (trong Userform1) thì tự động Last Name sẽ nhận giá trị ở cột tương ứng.
Đây là đoạn Code :
Private Sub ComboBox1_Change()
Dim i As Long
Dim lastrow As Long
Dim ws As Worksheet
Set ws = Sheets("Sheet1")
lastrow = ws.Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To lastrow
If Val(Me.ComboBox1.Value) = ws.Cells(i, "A") Then
Me.TextBox1.Value = ws.Cells(i, "B").Value
End If
Next i
End Sub
Em cảm ơn
![1533225924859.png 1533225924859.png](https://www.giaiphapexcel.com/diendan/data/attachments/158/158049-2b52923b229dfcad06496de84f6bf8a8.jpg?hash=K1KSOyKd_K)