Unable to lookup a date using vba vlookup

后端 未结 1 637
没有蜡笔的小新
没有蜡笔的小新 2021-01-19 04:27

I have an excel worksheet with column A containing dates and column B containing the respective days. Eg. A2=01/01/14 and B2=Wed and so on.

Im trying to retrieve th

1条回答
  •  无人及你
    2021-01-19 05:00

    VLookup is sensitive to data types. And your VBA routine is looking for a DATE data type, but such does not exist on an Excel worksheet. So you need to convert your string lookup_value to a data type compatible with what is on the worksheet. This could be a Long (for whole dates) or Double (if you are including times.

    Try:

    the_day = WorksheetFunction.VLookup(CLng(CDate(lookup_value)), lookup_table, 2, False)
    

    0 讨论(0)
提交回复
热议问题