Vba 到具有变量 SheetName 的 Vlookup

问题描述 投票:0回答:1

以下代码部分应使用变量 sheetname 执行 Vlookup。但是,vlookup 仅返回 0 而不是查找范围中的所需值,考虑到查找范围在这些具有变量名称的多个工作表中具有相同的结构,因此任何建议。

Dim SheetName As Variant: SheetName = DestinationWs.Name

Dim OldRemainingHoursLastRowFirst As Variant
OldRemainingHoursLastRowFirst = DestinationWs.Range("W3").End(xlDown).Row

DestinationWs.Range("L4").FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-2],""'" & StringVal & "'!R4C12:R" & OldRemainingHoursLastRowFirst & "C14"",2,0),0)"

excel vba variables vlookup variant
1个回答
0
投票

引用太多?

Dim SheetName As Variant
SheetName= DestinationWs.Name

DestinationWs.Range("L4").FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-2],INDIRECT('" & _
             SheetName & "'!R[" & OldRemainingLastRowFirst & "]C[12]:R[" & _
             OldRemainingLastRowFirst & "]C[12]), 2, 0)"
© www.soinside.com 2019 - 2024. All rights reserved.