Macro to total data from sheet6 onwards

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,603
Office Version
  1. 2021
Platform
  1. Windows
I have written code to put "Total Value" 3 rows after the last data on Col A & to sum Col B from B2 to the last row containing data in Col B


I need the above to occur from sheet6 onwards, but "Total Value" is only inserted 3 rows after the last data in Col A of the active sheet and Col B is also only summed on the active sheet


It would be appreciated if someone could kindly amend my code so that "Total Value" is only inserted 3 rows after the last data in Col A and Col B is summed from sheet6 to the last sheet containing data


Code:
 Sub Totals_Branches()
      With Application
.ScreenUpdating = False
.CutCopyMode = False
.Calculation = xlCalculationManual
End With
      Dim i As Long
      finalrow = Range("A65536").End(xlUp).Row
finalrow = Range("A65536").End(xlUp).Row + 2
      
      
    For i = 6 To Worksheets.Count
        With Sheets(i)
           Range("A" & finalrow + 3).Value = "Total Value"
Range("B" & finalrow + 3).Formula = "=sum(B2:B" & finalrow & ")"

            End With
       
    Next i
     With Application
.ScreenUpdating = True
.CutCopyMode = False
.Calculation = xlCalculationManual
End With
    
End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Try
Code:
Sub Totals_Branches()
With Application
    .ScreenUpdating = False
    .CutCopyMode = False
    .Calculation = xlCalculationManual
End With
      Dim i As Long
      
For i = 6 To Worksheets.Count
   
        With Sheets(i)
            finalrow = .Range("A65536").End(xlUp).Row
            .Range("A" & finalrow + 3).Value = "Total Value"
            .Range("B" & finalrow + 3).Formula = "=sum(B2:B" & finalrow & ")"
        End With
       
Next I
     
With Application
    .ScreenUpdating = True
    .CutCopyMode = False
    .Calculation = xlCalculationAutomatic
End With
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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