Auto-sum VBA Help

hercules89

New Member
Joined
Jan 24, 2019
Messages
3
Hey, I am working on some VBA macros for work but have ran into some trouble with the auto-sum function...basically I have various data-sets on the same sheet that I need to auto-sum the total for in column K but the problem lies in that there are 3 blank rows between each set of data...I have included below the code that I have got from recording the macro on Excel but this won't be good each day as the number of rows in each data sets will change so I am guessing I need a loop of some kind but I don't know how to write that...any help would be greatly appreciated :)

Range("K4").Select
Selection.End(xlDown).Select
Range("K83").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-78]C:R[-1]C)"
Range("K84").Select
Selection.End(xlDown).Select
Selection.End(xlDown).Select
Range("K95").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-9]C:R[-1]C)"
Range("K96").Select
Selection.End(xlDown).Select
Range("K99").Select
Selection.End(xlDown).Select
Range("K107").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-9]C:R[-1]C)"
Range("K108").Select
Selection.End(xlDown).Select
Selection.End(xlDown).Select
Range("K163").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-53]C:R[-1]C)"
Range("K164").Select
Selection.End(xlDown).Select
Selection.End(xlDown).Select
Range("K176").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-10]C:R[-1]C)"
Range("K177").Select
Selection.End(xlDown).Select

Thanks
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
what version excel ?

I'm guessing you want each block summed individually and not the total as you stated above as this would do =SUM(K5:K177)
 
Last edited:
Upvote 0
Hi & welcome to MrExcel
If col K is values, rather than formulae try
Code:
Sub hercules89()
   Dim Rng As Range
   
   For Each Rng In Range("K4", Range("K" & Rows.Count).End(xlUp)).SpecialCells(xlConstants).Areas
      Rng.Offset(Rng.Count).Resize(1).Formula = "=sum(" & Rng.Address & ")"
   Next Rng
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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