เหมือนจะยังไม่ตอบโจท์ครับอาจารย์ พอดีผมได้ลองอีกวิธีครับ โดยการใช้ Form เข้ามาช่วย
แต่ผมติดตรงที่เวลาผมกดปุ่ม ยืนยัน ผมอยากให้ข้อมูลที่เคยกรอกใช้ช่อง ComboBox และ TextBox เคลียออกไปด้วยครับ
แล้วให้เคอร์เซอร์ที่กระพริบไปอยู่ที่ ComboBox แรกครับ
Code: Select all
Private Comb_Arrow As Boolean
Private Sub ComboBox1_Change()
Dim i As Long
If Not Comb_Arrow Then
With Me.ComboBox1
.List = Worksheets("Name List").Range("A2", Worksheets("Name List").Cells(Rows.Count, "A").End(xlUp)).Value
.ListRows = Application.WorksheetFunction.Min(4, .ListCount)
.DropDown
If Len(.Text) Then
For i = .ListCount - 1 To 0 Step -1
If InStr(1, .List(i), .Text, vbTextCompare) = 0 Then .RemoveItem i
Next
.DropDown
End If
End With
End If
End Sub
Private Sub ComboBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Comb_Arrow = (KeyCode = vbKeyUp) Or (KeyCode = vbKeyDown)
If KeyCode = vbKeyReturn Then Me.ComboBox1.List = Worksheets("Name List").Range _
("A2", Worksheets("Name List").Cells(Rows.Count, "A").End(xlUp)).Value
End Sub
Private Sub CommandButton1_Click()
emptyRow = WorksheetFunction.CountA(Range("B:B")) + 1
Cells(emptyRow, 1).Value = ComboBox1.Value
Cells(emptyRow, 2).Value = TextBox2.Value
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
Private Sub userform_initialize()
ComboBox1.Value = ""
TextBox2.Value = ""
End Sub
You do not have the required permissions to view the files attached to this post.