任务:更改100个工作表中的总和范围。 每张表具有统一的命名约定,即“Client_” 每张表中的每个表都与工作表具有相同的名称。所以在“Client_Leaf”上有一个名为“Client_Leaf”的表。我一直在ActiveCell.FormulaR1C1行发生错误。这里是我的代码至今:声明变量等于工作表名称,以引用表中的表格
Sub fixFormulaRanges()
Application.ScreenUpdating = False
Dim Client As Worksheet
Dim ClientTable As ListObject
Dim varTableName As Variant
For Each Client In ActiveWorkbook.Worksheets
With Client
If CBool(InStr(1, .Name, "Client_", vbTextCompare)) Then
varTblName = .Name
Range("f8").Select
ActiveCell.FormulaR1C1 = _
"=SUMIF(varTblName & [Sector],RC[-2],varTblName & [Market Value])"
Range("F8:F20").Select
Selection.FillDown
End If
End With
Next Client
End Sub