Page 1 of 1

การเขียน VBA Vlook up ข้าม WorkSheet มีปัญหา

Posted: Thu May 04, 2017 10:24 am
by demeterrr
ปัญหาคือ นี้คือ code ที่ผมเขียนแต่ข้อมูลไม่มา

Code: Select all

Cells(3, 2).Value = Application.WorksheetFunction.VLookup(Sheet1.Cells(2, 2), Windows("DATA (Autosaved).xlsm").Sheet1.Range("mat"), 3, 0) / 1000
ผมต้องการดึงข้อมูลข้ามไฟล์ โดย กดปุ่ม Chose ในไฟล์ vac st ver 3 ชีท calculate แล้วพอ กดเลือก OptionButton "น้ำหนักมาตรฐาน" ตรงนี้ ต้องการ vlookup เพื่อดึงข้อมูลที่ ไฟล์ DATA (Autosaved) ชีท MAT ตาราง MAt คอลัม 3 มาใส่ตรง ไฟล์ vac st ver 3 ชีท calculte เซลล์ b3 แต่เกิด error
รบกวนด้วยครับ

Re: การเขียน VBA Vlook up ข้าม WorkSheet มีปัญหา

Posted: Thu May 04, 2017 10:50 pm
by snasui
:D ตัวอย่าง Code ครับ

Code: Select all

Private Sub OptionButton1_Click()
    With Workbooks("DATA (Autosaved).xlsm").Worksheets(1)
        If Application.CountIf(.Range("mat"), Cells(2, 2).Value) > 0 Then
            Cells(3, 2).Value = Application.WorksheetFunction.VLookup(Sheet1.Cells(2, 2), .Range("mat"), 3, 0) / 1000
        Else
            MsgBox "Data not found."
        End If
    End With
End Sub

Re: การเขียน VBA Vlook up ข้าม WorkSheet มีปัญหา

Posted: Fri May 05, 2017 10:32 am
by demeterrr
ได้แล้วครับขอบคุณมากครับ