VBA Code to Total Sections with Varying Number of Rows

Sawyer84

New Member
Joined
Oct 5, 2022
Messages
5
Office Version
  1. 365
Platform
  1. Windows
I would REALLY like some help with creating a code for section totals and then another code that adds a ‘total’ row. I just started learning about Macros and VBA codes last week, so this is all pretty new and a little overwhelming to me. I apologize in advance for the long description, it’s hard to explain verbally, let alone capture in words

For the section totals, those formulas need to go in columns G/I/K/N in the highlighted and bold rows. The problem is, there could be 1 section, or up to 5 or 6 sections, each having a different number of rows. For example, I would like the section total formula in cells G3/I3/K3/N3 to total up the rows below (items 20/30/40), but stop at the last part number before the next section. I would like to do the same for all sections and option sections, rental sections don’t have to have totals.

There will always be at least 1 section and 1 option section in each quote.

I added ‘higher level item’ data in column Q. I don’t currently have that information pulling in, but I can if it will make this easier. The ‘higher level item’ will identify which section parts belong to in a quote. For example, Section A in Quote 1 is Item 10, so every part in Section A will have a higher level item of 10. As you can see Quote 4 also has a Section A that is item 10. Part of the VBA code I currently have will insert 2 rows between quote numbers that are different, so hopefully that helps too.

For the total row, I would like to insert 2 rows above the first option section in each quote. In the first row that was inserted is where I would like ‘total’ in column D with right aligned. I would like the total formulas in columns G/I/K/N to add up the section totals.

1665097224648.png
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Try to attach a mini sheet via XL2BB
 
Upvote 0
Okay, I’ll give that a shot tomorrow. My brain was fried by the time I posted this, but as complicated as my ask is, I know the mini sheet will help a lot.
 
Upvote 0
I knew this was a difficult task, so I posted this on another forum as well. Someone responded this morning with a VBA code to try, which was 95% accurate. Would it be against protocol for me to post that code here and see if someone here can fine tune it?
 
Upvote 0
so I posted this on another forum as well
That is known as "Cross-Posting". Cross-posting is posting the same question in more than one forum.
It is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.
Be sure to follow & read the link at the end of the rule too!

Please provide links to the other places where you have posted this question.
If you do cross-post in the future, please be sure to provide the links every time and there shouldn’t be any problems.
 
Upvote 0
My question has been answered on the other forum with the link in my previous post. I’ll mark that one as solved.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,335
Members
452,636
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