VBA Code to auto sum data

MHamid

Active Member
Joined
Jan 31, 2013
Messages
472
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hello,

I have a count in column Q. After I insert a blank row, I would like to do a find for the blank cells in column Q and do a sum of the data above each blank cell.

For instance, each section is divided by each different fruits. Where the Total row is, that is where the total sum will be.
Column J Column Q
Apple 1
Apple 1
Apple 1
Apple 1
Apple 1
Apple Total 5
Banana 1
Banana 1
Banana 1
Banana Total 3
Cherry 1
Cherry 1
Cherry Total 2

Is this possible to do with vba code?

Thank you
 
Change this
Code:
Range("Q" & Rows.Count).End(xlUp).Offset(1).Formula = "=sum(" & Range("P:P").SpecialCells(xlBlanks).Offset(, 1).Address & ")"
to
Code:
   With Range("Q" & Rows.Count).End(xlUp).Offset(1)
      .Formula = "=sum(" & Range("P2:P" & .row - 1).SpecialCells(xlBlanks).Offset(, 1).Address & ")"
   End With
 
Upvote 0

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Hello,

Worked perfectly!! Thank you so much for your help.


Thank you
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,197
Members
453,021
Latest member
pingpong7117

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