tiredofit
Well-known Member
- Joined
- Apr 11, 2013
- Messages
- 1,924
- Office Version
- 365
- 2019
- Platform
- Windows
I have some data consisting of two columns, for example:
I want to calculate the Lower Quartile for every "block". By block I mean where the name is the same (ie in the sample above, I want to return a quartile value for a (= 100) and a quartile value for b (= 30).
This is my code (which works):
The problem is I have LOTS of data (about 1m rows) and the code above is slow (after 15 miuntes, it still hasn't finished running).
How can I speed things up?
Thanks
Rich (BB code):
Name Amount
a 100
a 200
a 300
b 20
b 50
b 60
I want to calculate the Lower Quartile for every "block". By block I mean where the name is the same (ie in the sample above, I want to return a quartile value for a (= 100) and a quartile value for b (= 30).
This is my code (which works):
Rich (BB code):
Dim DataArray() As Variant
DataArray() = wksData.Cells(1, 1).CurrentRegion.Value
Dim DataArrayRows As Long
DataArrayRows = UBound(DataArray(), 1)
Dim AmountArray() As Variant
ReDim AmountArray(1 To DataArrayRows, 1 To 1) As Variant
Dim AmountQArray() As Variant
ReDim AmountQArray(1 To DataArrayRows, 1 To 1) As Variant
Dim Counter As Long
For Counter = 2 To DataArrayRows - 1
AmountArray(Counter, 1) = DataArray(Counter, 2)
If DataArray(Counter, 1) <> DataArray(Counter + 1, 1) Then
On Error Resume Next
AmountQArray(Counter, 1) = Application.WorksheetFunction.Quartile_Exc(AmountArray(), 1)
On Error GoTo 0
ReDim AmountArray(1 To DataArrayRows, 1 To 1) As Variant
End If
If Counter = DataArrayRows - 1 Then
Counter = Counter + 1
AmountArray(Counter, 1) = DataArray(Counter, 2)
AmountQArray(Counter, 1) = Application.WorksheetFunction.Quartile_Exc(amountArray(), 1)
ReDim AmountArray(1 To DataArrayRows, 1 To 1) As Variant
End If
Next Counter
wksData.Cells(1, 5).Resize(DataArrayRows, 1).Value = AmountQArray()
The problem is I have LOTS of data (about 1m rows) and the code above is slow (after 15 miuntes, it still hasn't finished running).
How can I speed things up?
Thanks
Last edited: