简体   繁体   English

在VBA中执行多个vlookup操作

[英]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. 是否可以通过在3张纸中执行Vlookup操作将值返回到单元格,即要返回的值可能在三张纸之一中。 If so how can I approach this? 如果可以,我该如何处理? I am trying to create a macro using VBA. 我正在尝试使用VBA创建宏。

if there are no real differences between the worksheets you can use formulas instead of VBA using =IFERROR() and =VLOOKUP() 如果工作表之间没有真正的区别,则可以使用公式代替VBA,而使用=IFERROR()=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. 请记住,鉴于您的Excel是英文的,并且用逗号(“,”)作为分隔符,因此我已经写了公式,您可能需要将其翻译为默认语言和分隔符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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