Dim Rng As Range, i As Long
Private Sub UserForm_Initialize()
nap 'hanh dong truoc khi mo form
End Sub
'Click vao Combobox1, cac gia tri tung cot trong list se duoc add vao tung textbox
Private Sub ComboBox1_Click()
With ComboBox1
TextBox1.Value = .Column(0)
TextBox2.Value = .Column(1)
TextBox3.Value = .Column(2)
End With
End Sub
'Nhap nhung thay doi
Private Sub CommandButton1_Click()
Set Rng = Range("mammam")
i = ComboBox1.ListIndex + 1
Rng.Cells(i, 1) = TextBox1.Text
Rng.Cells(i, 2) = TextBox2.Text
Rng.Cells(i, 3) = TextBox3.Text
nap
End Sub
'Tao RowSource cho Combobox1
Sub nap()
Set Rng = Range("mammam")
With ComboBox1
If .ListCount > 0 Then .Clear 'bo list cu, cap nhat list moi
For i = 1 To Rng.Rows.Count
.AddItem Rng.Cells(i, 1)
.List(i - 1, 1) = Rng.Cells(i, 2)
.List(i - 1, 2) = Rng.Cells(i, 3)
.ListIndex = 0
Next
End With
End Sub