Formula in macro

sujittalukde

Well-known Member
Joined
Jun 2, 2007
Messages
520
I am running a macro which calculated subtotal and total but the GRAND TOTAL is taking the subtotal figure also. So I wnat to set the GRAND TOTAL formula in the macro itself so that GRAND TOTAL comes corrctly?

A picture is attached to clarify the matter.
Book8
ABCD
1A2
2B3
3C4
4AA5
5D6
6E7
7F8
8AA9
9G10
10H11
11I12
12AA13
13GRAND TOTAL63=((SUM(B1:B12))-(SUMIF(A1:B12,"aa",B1:B12)))
14This calculation has to be made in macro
Sheet1


How this can be done?
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

njimack

Well-known Member
Joined
Jun 17, 2005
Messages
7,764
Don't use SUM or SUMIF - use SUBTOTAL...

=SUBTOTAL(9,B1:B12)
 

sujittalukde

Well-known Member
Joined
Jun 2, 2007
Messages
520
THe macro I have use the sum function. I have made some modification to it so the GRAND TOTAL is changing So I need to change the formula of Grand Total
 

sujittalukde

Well-known Member
Joined
Jun 2, 2007
Messages
520
This is what I am already shown in my first post. This i wnat to set in the macro. HOw can I do it?
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Perhaps

Code:
Range("B13").Formula = "=SUM(B1:B12)-SUMIF(A1:A12,""aa"",B1:B12)"
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,101
Messages
5,768,101
Members
425,453
Latest member
bince

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
Top