2017-01-22 133 views
-1

我试图在R1C1格式中使用Vlookup公式中的变量。我无法获得表数组的语法。使用变量引用R1C1公式中的列和范围

我尝试这样做:

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 

我怎么能得到这个公式的工作?

回答

1

替换您的公式:

"=VLOOKUP(RC[" & -39 - a & "],'Tmp-UPCR'!C1:C" & a + 1 & "," & a + 1 & ",0)" 

但是,你能避免这一切SelectActiveCell和直接使用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 
+0

感谢您的解决方案,并建议更快的替代方案:)该公式工作正常。 – Aqua