下面的宏创建 i
新工作表的数量并将 E13 中的总计复制到单元格 F6 中的“总计”工作表中。我们还需要从“资源计算器”单元格 E14 中获取总计并将其复制到“总计”工作表单元格 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
最佳答案
我将利用 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
顺便说一句,注意可能的工作表名称拼写错误:您的叙述讲述了“资源计算器”,但在您的代码中您编写了“资源估算器”。我假设它们是同一张纸,并且“资源估算器”作为它的名字
关于vba - SumForumla : Two sumformula functions copied to two different cells in a "total" sheet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43207294/