I am using a User Form to select outputs for various cells. Then the worksheet is recalculated X times and that data stored in an array. I have had a lot of help getting this far but while I can sort a 1 dimensional array I have just not been able to figure it out for 2.
Because I am building a Monte Carlo simulation model there will be thousands of calculations when it is working and I do not want to have to enter all that data in a worksheet. It will slow it down too much. Because of th amount of data I feel that a Bubble sort will be slow not that I have been able to get that to work either.
The code includes data being entered into the worksheet but that is just for testing purposes.
Private Sub CommandButton1_Click() Dim SelRangeVarr() As String, SelRangeV, ArrData(), Test SelRangeVarr = Split(RefEdit1.Value, “,”) recalc = TextBox1 ‘No of times the worksheet is to be recalculated Range(“E1”).Select ‘Testing ReDim ArrData(recalc, UBound(SelRangeVarr)) ‘Redimensions the Data Array to the No of Required Calcuations and the No of OutPut Cells Arrout = “ArrCnt” & UBound(SelRangeVarr) For n = 0 To recalc – 1 ‘Limits to No calcs as Array start at 0 Application.Calculate ‘Calculates the Worksheet For i = LBound(SelRangeVarr) To UBound(SelRangeVarr) Set SelRangeV = Range(SelRangeVarr(i)) ‘Sets The Range ArrData(n, i) = SelRangeV.Value ‘Assigns the Value of the Calculation for Each Out Put Cell ‘TESTING ActiveCell.Value = n ActiveCell.Offset(0, 1).Value = ArrData(n, i) ActiveCell.Offset(1, 0).Select ‘TEST Ends Next ActiveCell.Offset(1, 0).Select Next BubbleSort2D ArrData, 1, 2 Range(“G1”).Select For i = LBound(SelRangeVarr) To UBound(SelRangeVarr) For n = 0 To recalc – 1 ‘Call QuickSort(ArrData, LBound(ArrData), UBound(ArrData)) ActiveCell.Value = ArrData(n, i) ActiveCell.Offset(1, 0).Select Next n ActiveCell.Offset(-recalc, 1).Select Next i Unload Me End Sub
Any suggestions will be greatly appreciated.
Thanks