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

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
=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,222,032
Messages
6,163,509
Members
451,839
Latest member
HonestZed

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