我试图在R1C1表单中使用Vlookup
公式中的变量。我无法获得表数组的语法。
我试过了:
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[" & -39 - a & "],'Tmp-UPCR'!C1:C&a+1,&a+1,0)" 'Check the formula
我使用的代码是:
Dim a As Integer
For a = 1 To i
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[" & -39 - a & "],'Tmp-UPCR'!C1:C&a+1,&a+1,0)" 'Check the formula
ActiveCell.Offset(0, 1).Select
Next a
我怎么能让这个公式起作用?
答案 0 :(得分:1)
用以下代码替换您的公式:
"=VLOOKUP(RC[" & -39 - a & "],'Tmp-UPCR'!C1:C" & a + 1 & "," & a + 1 & ",0)"
但是,您可以避免所有这些Select
和ActiveCell
,并直接使用下面的For
循环:
For a = 1 To i
' modify Column A below to the column where you want to put your formula
Range("A" & i).FormulaR1C1 = "=VLOOKUP(RC[" & -39 - a & "],'Tmp-UPCR'!C1:C" & a + 1 & "," & a + 1 & ",0)" 'Check the formula
Next a