Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用变量VBA替换RC公式值_Vba_Excel - Fatal编程技术网

用变量VBA替换RC公式值

用变量VBA替换RC公式值,vba,excel,Vba,Excel,我有下面的内容,就是把一个简单的Vlookup放入一个单元格 ActiveCell.FormulaR1C1=“=IFERROR(VLOOKUP(RC[-25],[MasterFood.xlsx]Sheet1!C1:C6,6,0),0)” 我需要用一个变量(称为LastColumn)替换-25,该变量已经计算过,因为每次程序运行时,列号都会改变。代码的完整部分如下所示 Dim LastColumn As Integer If WorksheetFunction.CountA(Cells) >

我有下面的内容,就是把一个简单的Vlookup放入一个单元格

ActiveCell.FormulaR1C1=“=IFERROR(VLOOKUP(RC[-25],[MasterFood.xlsx]Sheet1!C1:C6,6,0),0)”

我需要用一个变量(称为LastColumn)替换
-25
,该变量已经计算过,因为每次程序运行时,列号都会改变。代码的完整部分如下所示

Dim LastColumn As Integer

If WorksheetFunction.CountA(Cells) > 0 Then
    LastColumn = Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
    Cells(1, LastColumn + 1).Select
    ActiveCell.FormulaR1C1 = "ORDER"
End If

Cells(2, LastColumn + 1).Select

'Define Categories


For z = 2 To RowCount - 1

ActiveCell.FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-25],[MasterFood.xlsx]Sheet1!C1:C6,6,0),0)"
ActiveCell.Offset(1, 0).Select

Next
有什么想法吗?

给你:

ActiveCell.FormulaR1C1 = "=IFERROR(VLOOKUP(RC[" & LastColumn & "],[MasterFood.xlsx]Sheet1!C1:C6,6,0),0)"
请看。