
- 0.JPG (42.04 KiB) Viewed 30 times
จากรูปใช้ code ต่างกัน
Code: Select all
Private Sub txtIDNumber_Change()
LastRow = Sheets("Database").Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LastRow
If Sheets("Database").Cells(i, "A").Value = (Me.txtIDNumber) Then
Me.TextBox1 = Sheets("Database").Cells(i, 4).Value
Me.TextBox2 = Sheets("Database").Cells(i, 6).Value
Me.TextBox3 = Sheets("Database").Cells(i, 7).Value
Me.TextBox4 = Sheets("Database").Cells(i, 8).Value
Me.TextBox5 = Sheets("Database").Cells(i, 10).Value
Me.TextBox6 = Sheets("Database").Cells(i, 9).Value
Exit For
End If
Next
End Sub
รูปด้านช้าย ใช้ For i = 1 To LastRow
รูปด้านขวา ใช้ For i = 2 To LastRow
ผลออกมาตามรูป ข้อสังเกตุ คำตอบที่ได้เหมือนกัน และ ถูกต้อง
จึงไม่เข้าใจว่า For i = 1 To LastRow ไว้ทำไร
กลัวข้อมูลมีมากแล้วจะผิดแบบไม่รู้ตัว
ช่วยแนะนำด้วยครับว่าถูกต้องไหม หรือแก้ไขให้ถูกต้องที่สุด
อธิบาย
นำข้อมูลจากหัวข้อ จาก ComboBox มาหาข้อมูลในเซล พอเจอให้นำข้อมูลในบรรทัดนั้นมาแสดง
ใน textbox