VBA Dynamic Sum

Littlemalky

Board Regular
Joined
Jan 14, 2011
Messages
223
Here's the situation,

I'm using VBA to to paste three columns with a dynamic amount of rows being partnumbers, descriptions, and quantity. I have it xlDown and offset one row to sum that quantity, then I have it offset two rows down to paste another set of data below that, in which; again, I xlDown and offset and sum that portion of the quantities. However, below this second portion of quantities I need to create a "Grand Total" line right below that last quantity that sums the two totals on the page.

If it helps, with the first total, the cell directly to the left of it is entitled, "Total Raw Materials", and the other total is entitled, "Total In-House Blanks". Since all of this is dynamic including the placement of the "Grand Total" line, how do I search for the cell directly to the right of these titles and add it to my grand total sum formula in the cell right below the last total?
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
You'll need to modify the following:
Code:
Cells.Find(what:="Total Raw Materials", after:=Range("A1")).Offset(0,1).Select
 
Upvote 0
This should get you started
Code:
Sub LocateSums()
Dim C As Range
Dim D As Range
Dim x As Variant
Set C = Range("A:A").Find("Total Raw Materials", LookIn:=xlValues)
Set D = Range("A:A").Find("Total In-House Blanks", LookIn:=xlValues)
x = C.Value + D.Value
End Sub

lenze
 
Upvote 0
Thanks for the help lenze, I have a followup question for you: once the x is determined how do I state that in a formula within the activecell?

Something like?

ActiveCell.ForumulaR1C1 = x
 
Upvote 0
I overloked something when I posted.
You will need to use offset to add the totals. Something like this
Code:
x = C.Offset(0,1).Value + D.Offset(0,1).Value
All you need is
Code:
ActiveCell = x
lenze
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,875
Members
452,949
Latest member
Dupuhini

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