cameron.beyers
New Member
- Joined
- May 30, 2012
- Messages
- 2
I have a spreadsheet with Data in Columns A-H. Column B is an ID value that will repeat an unknown amount of times. For each Value in Column B I need to calculate the Median, Mean, and GeoMean for the corresponding range of "G_:H_"
Ex.
[TABLE="class: cms_table, width: 500, align: left"]
<tbody>[TR]
[TD]Column B[/TD]
[TD]Column G[/TD]
[TD]Column H[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]10[/TD]
[TD]5[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]13[/TD]
[TD]9[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]9[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]8[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]7[/TD]
[TD]3[/TD]
[/TR]
</tbody>[/TABLE]
For Column B = 2
I need to Calculate for the range "G2:H4"
I need the Median, Mean, and Geo Mean values to paste in Columns N-P for each different Station Index. My code only calculates for the first Station ID
Here is the code for what I have so far
Thanks in advance!!
Ex.
[TABLE="class: cms_table, width: 500, align: left"]
<tbody>[TR]
[TD]Column B[/TD]
[TD]Column G[/TD]
[TD]Column H[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]10[/TD]
[TD]5[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]13[/TD]
[TD]9[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]9[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]8[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]7[/TD]
[TD]3[/TD]
[/TR]
</tbody>[/TABLE]
For Column B = 2
I need to Calculate for the range "G2:H4"
I need the Median, Mean, and Geo Mean values to paste in Columns N-P for each different Station Index. My code only calculates for the first Station ID
Here is the code for what I have so far
Code:
Sub Median()
Dim r As Long
Dim stndx As String
Dim i As Long
Dim x As Integer
Application.Calculation = xlCalculationManual
r = Cells(Rows.Count, "A").End(xlUp).Row
x = 2
stndx = Cells(r, 2).Value[ATTACH]47030[/ATTACH]
For i = r To 8 Step -1
If Cells(i, 2).Value <> stndx Then
Cells(x + 1, 11).Value = Cells(i, 1).Value
Cells(x + 1, 12).Value = Cells(i, 2).Value
Cells(x + 1, 13).Value = Cells(i, 4).Value
Cells(x + 1, 14).Value = Application.Median(Range("G2:H" & i))
Cells(x + 1, 15).Value = Application.Average(Range("G2:H" & i))
End If
Next i
Application.Calculation = xlCalculationAutomatic
End Sub
Thanks in advance!!