下面的宏会创建i
个新工作表,并将E13中的总数复制到"总数"单元格F6中的表格。我们还需要从资源计算器"中获取总数。单元格E14并将其复制到" total"单元格F7。寻找一个好方法的建议。提前谢谢!
Sub Mac()
Sheets("total").Visible = True
Dim i As Integer, SumFormula As String
For i = 1 To Sheet1.Range("A15").Value
Sheets("Resource Estimator").Copy After:=Sheets(Sheets.Count)
ActiveSheet.Name = "Batch " & i
If i = 1 Then
SumFormula = "=SUM('" & ActiveSheet.Name & "'!E13" 'begin sum formula
Else
SumFormula = SumFormula & ",'" & ActiveSheet.Name & "'!E13" 'iterate sum formula
End If
Next i
SumFormula = SumFormula & ")" 'end sum formula
ThisWorkbook.Sheets("Total").Range("F6").Formula = SumFormula 'write sum formula to cell F6
End Sub
答案 0 :(得分:1)
我按如下方式利用 3D公式:
For i = 1 To Sheet1.Range("A15").Value
Sheets("Resource Estimator").Copy After:=Sheets(Sheets.Count)
ActiveSheet.Name = "Batch " & i
Next i
With Sheets("total")
.Visible = True
.Range("F6").Formula = "=sum('Batch 1:Batch " & i - 1 & "'!E13)"
.Range("F7") = Sheets("Resource Estimator").Range("E14")
End With
BTW,请注意可能的工作表名称拼写错误:您的叙述讲述了资源计算器"但是在你的代码中你写了#34;资源估算器"。我认为它们是同一张纸和资源估算器"正如其名称