Help Needed for Using VBA to Sum Totals till last row for Multiple Columns

vbanewlearner

New Member
Joined
Nov 27, 2017
Messages
2
Hi,

Q1: I have the following simplified chart (note: row can change so want to be able to do the totals at the last row). Total line want to make sure no decimals, bolded the entire Total row)

Q2: If want to add in column G that will return value % with 1 decimal which take column F $ divided by column D $ from row 8 to last row including total line

BCDEF
Row 8Alphabet$$$$
Row 9Alphabet$$$$
Row 10Alphabet$$$$
Row 11Alphabet$$$$
Row 12Alphabet$$$$
Row X(want to insert "Total" at the last row)(want to sum up from C8 all the way to last row)(want to sum up from D8 all the way to last row)(want to sum up from E8 all the way to last row)(want to sum up from F8 all the way to last row)

<tbody>
</tbody>
<strike></strike>Thank you.
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
The important bit of VBA is finding the last row in your table:
Code:
finalRow = Cells(Rows.Count, 1).End(xlUp).Row

To place the formula in the next row down, just add a "+ 1" to the end of it:
Code:
finalRow = Cells(Rows.Count, 1).End(xlUp).Row + 1

Then, just insert the formula into the first empty cell at the bottom of that column:
Code:
Range("B" & finalRow).Value = "=SUM(B2:B" & finalRow - 1 & ")"

For your second question, Just use relative referencing and add the formula to the entire row at once:
Code:
Range("B2:B" & finalRow - 1).FormulaR1C1 = "=RC[-1]/RC[-3]"

If you want the percent format:
Code:
Range("B2:B" & finalRow - 1).Style = "Percent"
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,360
Messages
6,124,491
Members
449,166
Latest member
hokjock

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