我正在尝试使用VBA将计算添加到多个工作表的使用范围中。问题是,我一直收到这个错误
'输入不匹配'
在阅读ws.Cells(countie, 12).FormulaR1C1 =...
这是我的语法 - 将解决这个问题,以便执行此语法?
Function JunctionTest()
Dim ws As Worksheet, countie As Long
For Each ws In ActiveWorkbook.Worksheets
With ws
If Application.WorksheetFunction.CountA(.Cells) <> 0 Then
LastRow = .Cells.Find(What:="*",After:=.Range("A1"),LookAt:=xlPart, _
LookIn:=xlFormulas, SearchOrder:=xlByRows,SearchDirection:=xlPrevious, _
MatchCase:=False).Row
Else
LastRow = 1
End If
For countie = 1 To LastRow
ws.Cells(countie, 12).FormulaR1C1 = "=RC7+RC8" / "=VLookup(A2, Totals!B2:R100, 3, False)"
Next countie
End Function
编辑 -
答案 0 :(得分:1)
&#34; = RC7 + RC8&#34; /&#34; = VLookup(A2,Totals!B2:R100,3,False)&#34;
从"=VLookup(
删除等号。
您不能将R1C1
符号与A1
符号混合使用:RC7+RC8
&amp; A2
不要混用
不要试图在VBA中构建一个FormulaR1C1,而是在工作表上正确运行公式,然后将工作公式打印到立即窗口
ws.Cells(countie, 12).FormulaR1C1 = "=RC7+RC8/VLOOKUP(RC1, Totals!R2C2:R100C18, 3, FALSE)"
Sub JunctionTest()
Dim ws As Worksheet
Dim lastRow As Long
For Each ws In ActiveWorkbook.Worksheets
With ws
lastRow = .Range("B" & .Rows.Count).End(xlUp).Row
.Range("L2:L" & lastRow).FormulaR1C1 = "=RC7+RC8/VLOOKUP(RC1, Totals!R2C2:R100C18, 3, FALSE)"
End With
Next
End Sub