snasui.com ยินดีต้อนรับ ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ ระบุ Version ของ Excel
Private Sub CommandButton1_Click()
Dim ProductId As String
ProductId = TextBox1.Text
lastRow = Worksheets("Bget").Cells(Rows.Count, 11).End(xlUp).Row
If ProductId = "" Then
MsgBox "กรุณากรอกรหัสอ้างอิง"
TextBox1.SetFocus
End If
For i = 2 To lastRow
If Worksheets("Bget").Cells(i, 11).Value = ProductId Then
TextBox2.Text = Worksheets("Bget").Cells(i, 3).Value
TextBox3.Text = Worksheets("Bget").Cells(i, 4).Value
TextBox4.Text = Worksheets("Bget").Cells(i, 5).Value
TextBox5.Text = Worksheets("Bget").Cells(i, 7).Value
TextBox6.Text = Worksheets("Bget").Cells(i, 8).Value
TextBox7.Text = Worksheets("Bget").Cells(i, 10).Value
End If
Next
If Worksheets("Bget").Cells(i, 11).Value <> ProductId Then
MsgBox "ไม่มีรหัสอ้างอิง"
TextBox1.SetFocus
End If
End Sub
Private Sub CommandButton1_Click()
Dim ProductId As String
ProductId = TextBox1.Text
lastRow = Worksheets("Bget").Cells(Rows.Count, 11).End(xlUp).Row
If ProductId = "" Then
MsgBox "กรุณากรอกรหัสอ้างอิง"
TextBox1.SetFocus
End If
x = Application.Match(ProductId, Worksheets("Bget").Cells(2, 11).Resize(lastRow).Value, 0)
If Not IsNumeric(x) Then
MsgBox "ไม่มีรหัสอ้างอิง"
TextBox1.SetFocus
End If
For i = 2 To lastRow
If Worksheets("Bget").Cells(i, 11).Value = ProductId Then
TextBox2.Text = Worksheets("Bget").Cells(i, 3).Value
TextBox3.Text = Worksheets("Bget").Cells(i, 4).Value
TextBox4.Text = Worksheets("Bget").Cells(i, 5).Value
TextBox5.Text = Worksheets("Bget").Cells(i, 7).Value
TextBox6.Text = Worksheets("Bget").Cells(i, 8).Value
TextBox7.Text = Worksheets("Bget").Cells(i, 10).Value
End If
Next
End Sub