I found this macro in the forums here to add a formula in 4 different worksheets. Is there a way to simply have the macro insert the formulas in ALL worksheets within the workbook that are not hidden instead of just the 4 listed?
PHP:
Sub Insert_SUM_Formulas()
Dim ws As Worksheet
Dim Lastrow As Long, Lastcol As Long
For Each ws In Sheets(Array("Name1", "Name2", "Name3", "Name4"))
Lastrow = ws.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
Lastcol = ws.Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
Range(Cells(Lastrow, "D"), Cells(Lastrow, Lastcol)).FormulaR1C1 = "=SUM(R1C:R" & Lastrow - 1 & "C)"
Next ws
End Sub