I have a large set of data and I need to calculate the median of certain values which are based on certain conditions in an if statement in a loop - in the code below I need to calculate the median of all the value_1 fields
- does someone have code that can be used to calculate a median like this? (I don't want to access the worksheet function given the amount of data I am processing)
- I also need to output all the data_set(i, 12) and data_set(i, 13) values when the condition is met (so when condition_1 > 5) in a list somewhere else in the excel workbook so that I can see them; how can I do this?
Many thanks
- does someone have code that can be used to calculate a median like this? (I don't want to access the worksheet function given the amount of data I am processing)
- I also need to output all the data_set(i, 12) and data_set(i, 13) values when the condition is met (so when condition_1 > 5) in a list somewhere else in the excel workbook so that I can see them; how can I do this?
Many thanks
Code:
Sub conditional_median_calc()
Application.ScreenUpdating = False
Dim data_set As Variant
data_set = Range("A3:D50000")
Dim i As Long
For i = 1 to UBound(data_set, 1)
condition_1 = data_set(i, 10)
If condition_1 > 5 Then
value_1 = data_set(i, 12) + data_set(i, 13) + data_set(i, 14)
End If
Next i
End Sub