VBA find Max, Min and Sum

MikeCook69

New Member
Joined
Jun 4, 2018
Messages
4
I have 2 worksheets. The first work sheet has my raw data. The second worksheet has a list that I am trying to find the max and min values of the raw data and the sum. My data is not sorted.

Worksheet 1
[TABLE="width: 200"]
<tbody>[TR]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[/TR]
[TR]
[TD]g[/TD]
[TD]1[/TD]
[TD]4[/TD]
[TD]10[/TD]
[/TR]
[TR]
[TD]e[/TD]
[TD]2[/TD]
[TD]3[/TD]
[TD]12[/TD]
[/TR]
[TR]
[TD]g[/TD]
[TD]1[/TD]
[TD]2[/TD]
[TD]14[/TD]
[/TR]
[TR]
[TD]g[/TD]
[TD]4[/TD]
[TD]4[/TD]
[TD]16[/TD]
[/TR]
[TR]
[TD]e[/TD]
[TD]3[/TD]
[TD]5[/TD]
[TD]14[/TD]
[/TR]
[TR]
[TD]f[/TD]
[TD]2[/TD]
[TD]6[/TD]
[TD]13[/TD]
[/TR]
[TR]
[TD]e[/TD]
[TD]4[/TD]
[TD]3[/TD]
[TD]10[/TD]
[/TR]
[TR]
[TD]g[/TD]
[TD]2[/TD]
[TD]2[/TD]
[TD]12[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

Worksheet 2
[TABLE="width: 200"]
<tbody>[TR]
[TD]A[/TD]
[TD]Min B[/TD]
[TD]Max C[/TD]
[TD]Sum D[/TD]
[/TR]
[TR]
[TD]g[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]e[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

So I'm trying to get the following results.

[TABLE="width: 200"]
<tbody>[TR]
[TD]A[/TD]
[TD]Min B[/TD]
[TD]Max C[/TD]
[TD]Sum D[/TD]
[/TR]
[TR]
[TD]g[/TD]
[TD]1[/TD]
[TD]4[/TD]
[TD]52[/TD]
[/TR]
[TR]
[TD]e[/TD]
[TD]2[/TD]
[TD]4[/TD]
[TD]36[/TD]
[/TR]
</tbody>[/TABLE]

I was trying to use a loop with nested if statements but I'm not sure if that is the most efficient method. I also might be making this more complicated that I need to.
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
[Table="width:, class:head"][tr=bgcolor:#E0E0F0][th] [/th][th]
A
[/th][th]
B
[/th][th]
C
[/th][th]
D
[/th][th]
E
[/th][th]
F
[/th][th]
G
[/th][th]
H
[/th][th]
I
[/th][/tr]
[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
1
[/td][td]g[/td][td]
1​
[/td][td]
4​
[/td][td]
10​
[/td][td][/td][td][/td][td]Min B[/td][td]Max C[/td][td]Sum[/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
2
[/td][td]e[/td][td]
2​
[/td][td]
3​
[/td][td]
12​
[/td][td][/td][td]g[/td][td]
1​
[/td][td]
4​
[/td][td]
52​
[/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
3
[/td][td]g[/td][td]
1​
[/td][td]
2​
[/td][td]
14​
[/td][td][/td][td]e[/td][td]
2​
[/td][td]
4​
[/td][td][/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
4
[/td][td]g[/td][td]
4​
[/td][td]
4​
[/td][td]
16​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
5
[/td][td]e[/td][td]
3​
[/td][td]
5​
[/td][td]
14​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
6
[/td][td]f[/td][td]
2​
[/td][td]
6​
[/td][td]
13​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
7
[/td][td]e[/td][td]
4​
[/td][td]
3​
[/td][td]
10​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
8
[/td][td]g[/td][td]
2​
[/td][td]
2​
[/td][td]
12​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]
[/table]
[Table="width:, class:grid"][tr][td]Sheet: Sheet18[/td][/tr][/table]

Formula in cell I2:
=SUMIFS($D$1:$D$8,$A$1:$A$8,F2,$B$1:$B$8,">="&G2,$C$1:$C$8,"<="&H2)

Code:
Sub Macro1()


    Range("I2").Formula = "=SUMIFS($D$1:$D$8,$A$1:$A$8,F2,$B$1:$B$8,"">=""&G2,$C$1:$C$8,""<=""&H2)"


End Sub
 
Upvote 0

Forum statistics

Threads
1,224,747
Messages
6,180,714
Members
452,995
Latest member
isldboy

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