ดึงข้อมูลข้าม file แล้วให้มาแสดงที่ userform
Posted: Sat Oct 24, 2020 12:59 pm
รบกวนท่านอาจารย์ ผมต้องการ ดึงข้อมูลอีก file แล้วหาข้อมูลคอลั่มA จากfile database ถ้าข้อมูลตรงกับ textbox ให้ดึงข้อมูลที่คอลั่ม B มาแสดงที่ label ขอบคุณครับ
คลังคำตอบแห่งความรู้จากคนไทย เพื่อโลกที่ต้องการเข้าใจในสิ่งเล็ก ๆ อย่างลึกซึ้ง
http://www.snasui.com/
ขอโทษทีครับ รีบมากเลยลืมแนบ codesnasui wrote: Sat Oct 24, 2020 7:54 pmกรุณาอธิบายเพิ่มเติมว่าใช้ไฟล์ไหนดึงข้อมูลจากไฟล์ไหน ด้วย Code ใน Form หรือ Module ใด Code ชื่อว่าอะไร ติดขัดบรรทัดใด จะได้เข้าถึงปัญหาได้โดยไวครับ
Code: Select all
Private Sub CommandButton1_Click()
Dim wb As Workbook
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set wb = Workbooks.Open("D:\Sooksun\Improvement\visual\Database.xlsm", False, False)
With wb
Dim nRow As String
nRow = wb.Sheets("Data").Columns(1).Find(txt_Vinno.Text).Row
Sheet1.Activate
If Err.Number = 91 Then
txt_Vinno.RowSource = "txt_Vinno.Text"
MsgBox "äÁèÁÕ¢éÍÁÙÅ Vin number"
Exit Sub
End If
txt_Vinno = Cells(nRow, 1)
lbl_model.Caption = Cells(nRow, 2)
End With
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End SubCode: Select all
'Other code
Dim nRow As Integer
nRow = wb.Sheets("Data").Columns(1).Find(txt_Vinno.Text).Row
Sheet1.Activate
If Err.Number = 91 Then
txt_Vinno.RowSource = "txt_Vinno.Text"
MsgBox "ไม่มีข้อมูล Vin number"
Exit Sub
End If
UserForm1.lbl_model.Caption = wb.Sheets("Data").Cells(nRow, 2).Value
'Other codeได้แล้วครับขอบคุณครับsnasui wrote: Tue Oct 27, 2020 9:11 pmตัวอย่าง Code ครับ
Code: Select all
'Other code Dim nRow As Integer nRow = wb.Sheets("Data").Columns(1).Find(txt_Vinno.Text).Row Sheet1.Activate If Err.Number = 91 Then txt_Vinno.RowSource = "txt_Vinno.Text" MsgBox "ไม่มีข้อมูล Vin number" Exit Sub End If UserForm1.lbl_model.Caption = wb.Sheets("Data").Cells(nRow, 2).Value 'Other code