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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
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,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

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