不使用Excel VBA在工作簿中的所有工作表上更新公式

我正在尝试在工作簿的每个工作表上做一些简单的计算。 但是,计算不会在所有工作表上更新。 你能帮我把计算结果显示在工作簿中的所有表格上吗?

这是我到目前为止:

Sub SearchFolders() 'UpdatebySUPERtoolsforExcel2016 Dim xOut As Worksheet Dim xWb As Workbook Dim xWks As Worksheet Dim xRow As Long Dim xFound As Range Dim xStrAddress As String Dim xFileDialog As FileDialog Dim xUpdate As Boolean Dim xCount As Long Application.ScreenUpdating = False Set xWb = ActiveWorkbook For Each xWks In xWb.Sheets xRow = 1 With xWks .Cells(xRow, 12) = "Meas-LO" .Cells(xRow, 13) = "Meas-Hi" .Cells(xRow, 14) = "Marginal" LastRow = ActiveSheet.UsedRange.Rows.Count Range("L2").Formula = "=G2+I2" Range("L2").AutoFill Destination:=Range("L2:L" & LastRow) Range("M2").Formula = "=I2-F2" Range("M2").AutoFill Destination:=Range("M2:M" & LastRow) End With Application.ScreenUpdating = True 'turn it back on Next xWks End Sub 

在For循环中, Activate每个工作表,如下所示。 如果你没有激活工作表,第一个工作表将始终保持激活状态,variables“LastRow”中包含的值将不会是你想要的(从第二次迭代开始),因为它使用了activesheet。

 Sub SearchFolders() 'UpdatebySUPERtoolsforExcel2016 Dim xOut As Worksheet Dim xWb As Workbook Dim xWks As Worksheet Dim xRow As Long Dim xFound As Range Dim xStrAddress As String Dim xFileDialog As FileDialog Dim xUpdate As Boolean Dim xCount As Long Application.ScreenUpdating = False Set xWb = ActiveWorkbook For Each xWks In xWb.Sheets xRow = 1 With xWks .Activate 'Activating the worksheet .Cells(xRow, 12) = "Meas-LO" .Cells(xRow, 13) = "Meas-Hi" .Cells(xRow, 14) = "Marginal" LastRow = ActiveSheet.UsedRange.Rows.Count Range("L2").Formula = "=G2+I2" Range("L2").AutoFill Destination:=Range("L2:L" & LastRow) Range("M2").Formula = "=I2-F2" Range("M2").AutoFill Destination:=Range("M2:M" & LastRow) End With Application.ScreenUpdating = True 'turn it back on Next xWks End Sub