简体   繁体   English

具有动态查找值的公式 VLOOKUP

[英]Formula VLOOKUP with dynamic lookup value

I want to let the lookup vale of a vlookup dynamic with the loop counter, I tried:我想用循环计数器让 vlookup 的查找值动态,我试过:

WS1.Cells(4 + j - 1, 3 + ((i - 1) * 9)).Formula = "=VLOOKUP(" & WS1.Cells(4 + j - 1, 4 + ((i - 1) * 9)) & ",WS2NAME!B:C,2,FALSE)"

I though that " & WS1.Cells(4 + j - 1, 4 + ((i - 1) * 9)) & " would return the cell name, (eg B3, D5, ...) but it returns blank when I run the macro in excel.我虽然" & WS1.Cells(4 + j - 1, 4 + ((i - 1) * 9)) & "会返回单元格名称,(例如 B3,D5,...)但它返回空白时我在 excel 中运行宏。

Any suggestions?有什么建议么?

Using R1C1 referencing would be easier here:在这里使用 R1C1 引用会更容易:

WS1.Cells(4 + j - 1, 3 + ((i - 1) * 9)).FormulaR1C1 = "=VLOOKUP(RC[1],WS2NAME!C2:C3,2,FALSE)"

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

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