Hello everyone,
It's taking forever to calculate and write MIN and MAX based on 2 criteria for a few hundred rows. The current methods that I have written are too slow and/or give me some weird errors.
Sheet1, ColumnA(amounts), ColumnB(salesperson), ColumnC(category)
On Sheet 2, based on salespersonin ColumnA and category in ColumnB, need to write MIN amount in ColumnC and MAX amount in ColumnD
Example code for MIN:
1) Attempt:
- Very slow
2) Attempt:
- Slow
- Changes to every 2 rows instead of every 1 row as intended
Only 1) works and its 222222 slow...
Please advise if you know of a faster process way.
Maybe building an array of amounts based on the 2 criteria and then building another array based on MIN and MAX of the first array values/elements. Is this a slower process because of the iteration?
Maybe some other way?
Thank you in advance!!!
It's taking forever to calculate and write MIN and MAX based on 2 criteria for a few hundred rows. The current methods that I have written are too slow and/or give me some weird errors.
Sheet1, ColumnA(amounts), ColumnB(salesperson), ColumnC(category)
On Sheet 2, based on salespersonin ColumnA and category in ColumnB, need to write MIN amount in ColumnC and MAX amount in ColumnD
Example code for MIN:
1) Attempt:
VBA Code:
sheet2.Range("I2:I" & Lastrow).FormulaR1C1 = "=AGGREGATE(15,3,1/((Sheet1!C[-1]=RC[-2])*(Sheet1!C[]=RC[-1]))*Sheet1!C[-2],1)"
shgroup.Range("I2:I" & Lastrow).Style = "Currency"
2) Attempt:
VBA Code:
sheet2.Range("I2:I" & Lastrow).FormulaR1C1 = "=MIN((IF(Sheet1!C[-1]=RC[-2],IF(Sheet1!C[]=RC[-1],Sheet1!C[-2])))"
shgroup.Range("I2:I" & Lastrow).FormulaArray = Range("I2:I" & Lastrow2).Formula
shgroup.Range("I2:I" & Lastrow).Style = "Currency"
- Changes to every 2 rows instead of every 1 row as intended
Only 1) works and its 222222 slow...
Please advise if you know of a faster process way.
Maybe building an array of amounts based on the 2 criteria and then building another array based on MIN and MAX of the first array values/elements. Is this a slower process because of the iteration?
Maybe some other way?
Thank you in advance!!!