Macro - Sum of all "A" corresponding value from column F:I

baps2013

New Member
Joined
Apr 16, 2013
Messages
2
Hello,

I am new to excel VBA , need you help for this problem.

I have attached data file for which I need a Marco to get the sum of each grade value corresponding from Q1 to Q4.

Result explected:

GradeTotal
A1068 (result)
B
C
D

<tbody>
</tbody>



Attached excel file

Grade Q1 Q2 Q3Q4
A 108050100
A 10105010
B 35353535
B 60456078
A 45785690
D 10677810
A 35351035
A 40603589
B 20507890
B 10101010
A 35353535
D 60353540

<tbody>
</tbody><colgroup><col span="5"><col span="3"><col></colgroup>
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
=SUM(((F2:F13) + (G2:G13)+(H2:H13)+(I2:I13)) * (A2:A13="A"))
=SUM(((F2:F13) + (G2:G13)+(H2:H13)+(I2:I13)) * (A2:A13="B"))
=SUM(((F2:F13) + (G2:G13)+(H2:H13)+(I2:I13)) * (A2:A13="C"))
=SUM(((F2:F13) + (G2:G13)+(H2:H13)+(I2:I13)) * (A2:A13="D"))

Assuming your data starts in A1

You'll need to enter these as array formulas so instead of pressing "Enter" once you've pasted it, you'll need to do "Ctrl" + "Shift" + "Enter"
 
Upvote 0
This macro puts the results in columns K:L

Code:
[color=darkblue]Sub[/color] Annual_Grade_Totals()
    Range("K1:L1").Value = Array("Grade", "Annual Total")
    Range("K2:K5").Value = Application.Transpose(Array("A", "B", "C", "D"))
    Range("L2").Value = Evaluate("=SUMPRODUCT(--(A2:A13=""A""),(F2:F13+G2:G13+H2:H13+I2:I13))")
    Range("L3").Value = Evaluate("=SUMPRODUCT(--(A2:A13=""B""),(F2:F13+G2:G13+H2:H13+I2:I13))")
    Range("L4").Value = Evaluate("=SUMPRODUCT(--(A2:A13=""C""),(F2:F13+G2:G13+H2:H13+I2:I13))")
    Range("L5").Value = Evaluate("=SUMPRODUCT(--(A2:A13=""D""),(F2:F13+G2:G13+H2:H13+I2:I13))")
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Upvote 0

Forum statistics

Threads
1,214,416
Messages
6,119,384
Members
448,889
Latest member
TS_711

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