简体   繁体   中英

Excel VLookup VBA cant refer to another worksheet

Public Function Lohn(ID)

Lohn = Application.WorksheetFunction.VLookup(ID, ThisWorkbook.Worksheets("Arbeiter").Range("A:D"), 2, 0)

End Function

I cant access the Worksheet "Arbeiter" its just doesn't give me a Value back can some one help me

There is nothing more code in the Section if anyone wants to know ID is numeric

在此处输入图像描述

在此处输入图像描述

I got it to work after changing from Application.WorksheetFunction.VLookup to Application.VLookup

Be careful to load in an ID with the same data type as the value in the cell. It gave me error 2042 when i used a string as the ID but was able to work properly when I put in an integer.

Here is your function after my changes:

Public Function Lohn(ID)

Lohn = Application.VLookup(ID, ThisWorkbook.Worksheets("Arbeiter").Range("A:D"), 2, False)

End Function

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM