简体   繁体   中英

Performing multiple vlookup operation in VBA

I have a logical doubt. Is it possible to return a value to a cell by performing Vlookup operation in 3 sheets, ie the value to be returned might be in one of the three sheets. If so how can I approach this? I am trying to create a macro using VBA.

if there are no real differences between the worksheets you can use formulas instead of VBA using =IFERROR() and =VLOOKUP()

An example would be:

=IFERROR(VLOOKUP(valueToLookFor,sheet1Range,columnNumber,FALSE),IFERROR(VLOOKUP(valueToLookFor,sheet2Range,columnNumber,FALSE),VLOOKUP(valueToLookFor,sheet3Range,columnNumber,FALSE)))

This would just perform the search on the first sheet, if the value isn't there it will return an error, hence looking in the following sheet etc.

Bear in mind I've written the formula given your Excel is in English with commas (",") as separators, you might need to translate it in you default language and separators.

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