Copy Paste Subtotal Row and Formula On Every Sheet Excluding Specific Sheets - HELP!

magnum5az

New Member
Joined
Jun 21, 2017
Messages
16
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

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!
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
LR = Range("A" & Rows.Count).End(xlUp).Row 
This line should be in the loop...?


For Each sht In ThisWorkbook.Worksheets
LR = sht.Range("A" & Rows.Count).End(xlUp).Row 
 
Last edited:
Upvote 0
I am not sure of your question about the line of code. When I update the macro with your revision it still copy's the data all over the place.
 
Upvote 0

Forum statistics

Threads
1,223,901
Messages
6,175,277
Members
452,629
Latest member
SahilPolekar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top