snasui.com ยินดีต้อนรับ ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ ระบุ Version ของ Excel
Private Sub CommandButton1_Click()
Dim q, p As Long
q = Application.WorksheetFunction.CountA(Sheet2.Range("B:B"))
If Application.CountIf(Sheet2.Range("a:a"), Me.TextBox1.Text) = 0 Then
MsgBox "Not found.", vbInformation
Exit Sub
Else
For p = 2 To 4
Me.Controls("TextBox" & p).Text = Application.WorksheetFunction.VLookup( _
CDbl(Me.TextBox1.Text), Sheet2.Range("A:D"), p, 0)
Next p
End If
Do
r = r + 1
Loop Until Cells(r, 1) = ""
Cells(r, 1) = TextBox1.Text
Cells(r, 2) = TextBox2.Text
Cells(r, 3) = TextBox3.Text
Cells(r, 4) = TextBox4.Text
Cells(r, 5) = TextBox5.Text
Cells(r, 6) = TextBox6.Text
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
End Sub
Private Sub CommandButton1_Click()
Dim q, p As Long
q = Application.WorksheetFunction.CountA(Sheet2.Range("B:B"))
If Application.CountIf(Sheet2.Range("a:a"), Me.TextBox1.Text) = 0 Then
MsgBox "Not found.", vbInformation
Exit Sub
Else
For p = 2 To 4
Me.Controls("TextBox" & p).Text = Application.WorksheetFunction.VLookup( _
CDbl(Me.TextBox1.Text), Sheet2.Range("A:D"), p, 0)
Next p
End If
Do
r = r + 1
Loop Until Cells(r, 1) = ""
Cells(r, 1) = TextBox1.Text
Cells(r, 2) = TextBox2.Text
Cells(r, 3) = TextBox3.Text
Cells(r, 4) = TextBox4.Text
Cells(r, 5) = TextBox5.Text
Cells(r, 6) = TextBox6.Text
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
End Sub
Private Sub CommandButton1_Click()
Do
r = r + 1
Loop Until Cells(r, 1) = ""
Cells(r, 1) = TextBox1.Text
Cells(r, 2) = TextBox2.Text
Cells(r, 3) = TextBox3.Text
Cells(r, 4) = TextBox4.Text
Cells(r, 5) = TextBox5.Text
Cells(r, 6) = TextBox6.Text
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
End Sub
Private Sub TextBox1_AfterUpdate()
Dim q, p As Long
q = Application.WorksheetFunction.CountA(Sheet2.Range("B:B"))
If Me.TextBox1.Text = "" Or Application.CountIf(Sheet2.Range("a:a"), Me.TextBox1.Text) = 0 Then
MsgBox "Not found.", vbInformation
Exit Sub
Else
For p = 2 To 4
Me.Controls("TextBox" & p).Text = Application.WorksheetFunction.VLookup( _
CDbl(Me.TextBox1.Text), Sheet2.Range("A:D"), p, 0)
Next p
End If
End Sub
คีย์ค่าลงใน TextBox1 แล้ว Enter จะเป็นการเติมค่า TextBox อื่น ๆ ให้
Private Sub CommandButton1_Click()
Do
r = r + 1
Loop Until Cells(r, 1) = ""
Cells(r, 1) = TextBox1.Text
Cells(r, 2) = TextBox2.Text
Cells(r, 3) = TextBox3.Text
Cells(r, 4) = TextBox4.Text
Cells(r, 5) = TextBox5.Text
Cells(r, 6) = TextBox6.Text
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
End Sub
Private Sub TextBox1_AfterUpdate()
Dim q, p As Long
q = Application.WorksheetFunction.CountA(Sheet2.Range("B:B"))
If Me.TextBox1.Text = "" Or Application.CountIf(Sheet2.Range("a:a"), Me.TextBox1.Text) = 0 Then
MsgBox "Not found.", vbInformation
Exit Sub
Else
For p = 2 To 4
Me.Controls("TextBox" & p).Text = Application.WorksheetFunction.VLookup( _
CDbl(Me.TextBox1.Text), Sheet2.Range("A:D"), p, 0)
Next p
End If
End Sub
คีย์ค่าลงใน TextBox1 แล้ว Enter จะเป็นการเติมค่า TextBox อื่น ๆ ให้