So, I have a code that I have been working on now for 2 days and have hit a roadblock and not sure how to fix it. I am hoping one of you Guru's will simply look at it and see a line of code that is entered incorrectly or something. So here it is
Essentially, what I am trying to do is to reference my main reports subtotal row that has some formatting and to copy/paste that row in each of my sheets excluding a few and then after insert a subtotal formula into the subtotal row in a few columns.
At the moment, if I pause the code right before the Next sht line of code it works fine for one sheet, its when I have it running the loop that the subtotals start getting pasted all over the place in the different sheets instead of following the logic to find the last active row in Column A and paste the subtotal line there. Also, I am getting a runtime error once it completes the code and flagging the line sht.Range("A" & LR + 1).Select
Any help on this is much appreciated!
Code:
Sub Subtotals()
Dim sht As Worksheet
Dim subs As Range
Dim lastrow As Long
Dim LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
Set subs = Range("NOIGrandtotal") 'subtotal row with formatting from main sheet
For Each sht In ThisWorkbook.Worksheets
Select Case sht.Name
Case "NOI", "Yardi Report", "NOI Summary", "NOI - Combined Property", "Cash Flow Summary", "Comparison", "FMV", "SP FMV"
Case Else
subs.Copy
sht.Activate
sht.Range("A" & LR + 1).Select
Selection.Insert Shift:=xlDown
'Formulas in the Subtotal Row
Range("J" & LR + 1).Formula = "=SUM(J7:J" & LR & ")"
Range("L" & LR + 1).Formula = "=SUM(L7:L" & LR & ")"
Range("M" & LR + 1).Formula = "=SUM(M7:M" & LR & ")"
Range("N" & LR + 1).Formula = "=SUM(N7:N" & LR & ")"
Range("Q" & LR + 1).Formula = "=SUM(Q7:Q" & LR & ")"
Range("R" & LR + 1).Formula = "=SUM(R7:R" & LR & ")"
Range("S" & LR + 1).Formula = "=SUM(S7:S" & LR & ")"
Application.CutCopyMode = False
Columns.AutoFit
Union(Columns("I"), Columns("K"), Columns("P")).ColumnWidth = 1.57
Columns("A").ColumnWidth = 5.29
End Select
Next sht
Application.CutCopyMode = False
End Sub
Essentially, what I am trying to do is to reference my main reports subtotal row that has some formatting and to copy/paste that row in each of my sheets excluding a few and then after insert a subtotal formula into the subtotal row in a few columns.
At the moment, if I pause the code right before the Next sht line of code it works fine for one sheet, its when I have it running the loop that the subtotals start getting pasted all over the place in the different sheets instead of following the logic to find the last active row in Column A and paste the subtotal line there. Also, I am getting a runtime error once it completes the code and flagging the line sht.Range("A" & LR + 1).Select
Any help on this is much appreciated!