A model calculates a worksheet a number of times and outputs the results to an array. The array is re-dimensioned at startup based on number of calculations required. At present after calculation it enters the data into a worksheet and then finds the max and min from the values in the worksheet range. What I would like to do i skip having to enter data and return the max and min values form the array. everything I have tried so far either returns 0 or the max value for both min and max.
I would also like to sort the array and return all the bins without entering them in the worksheet but one thing at a time .
Thanks very much
This is the code I am using
Sub Recalculate() ‘Recalculates the WorkBook Dim Calc_ Worksheets(startSht).Select Set Output = Application.InputBox(prompt:=”Please select the 1st Output Range.”, Title:=”SPECIFY RANGE”, Type:=8) Set OutPutLabel = Application.InputBox(prompt:=”Please select Label for the 1st Output Range.”, Title:=”SPECIFY RANGE”, Type:=8) Output = Output.Address Dim rt Worksheets(wsC).Select ‘Name in WB of the sheet to be used Cells.Select ‘Just to make sure no data Selection.ClearContents Range(“A1”).Select rt = InputBox(“No Calcs”) ‘Asks for number of times to recalculate ReDim Calc_(rt) ‘Redimensions the array to number of calcs to be done For i = 1 To rt ‘Loops number of calcualtions Application.Calculate ‘Recalculates workbook Calc_(i) = Worksheets(“Results”).Range(Output).Value ‘Range value Next i For i = 1 To rt ‘Enters data from array into stats worksheet Worksheets(wsC).Range(“A” & i).Value = Calc_(i) Next i Columns(“A:D”).NumberFormat = “$#,##0” Call QuickSort(Calc_, LBound(Calc_), UBound(Calc_)) ‘Calls QuickSort to sort the results into ascending order For i = 1 To rt ‘ ‘Loops number of calcualtions in the sorted array Worksheets(wsC).Range(“B” & i).Value = Calc_(i) ‘Enters data from array into stats worksheet Next i Perstep = 0.05 Columns(“C”).NumberFormat = “#0%” For i = 1 To 20 Worksheets(wsC).Range(“c” & i).Value = Perstep If i = 20 Then ‘Required does not like it if it runs to 1 by addition LOOK INTO Worksheets(wsC).Range(“D” & i).Value = Application.WorksheetFunction.Percentile(Range(Cells(1, 2), Cells(rt, 2)), 1) Else Worksheets(wsC).Range(“D” & i).Value = Application.WorksheetFunction.Percentile(Range(Cells(1, 2), Cells(rt, 2)), Perstep) Perstep = Perstep + 0.05 End If Next i Maxv = Application.WorksheetFunction.Max(Cells(1, 2), Cells(rt, 2)) MinV = Application.WorksheetFunction.Min(Cells(1, 2), Cells(rt, 2)) Maxv = Application.WorksheetFunction.RoundUp(Maxv, -6) MinV = Application.WorksheetFunction.RoundDown(MinV, -6) StepV = (Maxv – MinV) / 20 MinV = MinV – StepV For i = 1 To 20 Worksheets(wsC).Range(“E” & i).Value = MinV MinV = MinV + StepV Next i Range(Range(“B1”), Range(“B1”).End(xlDown)).Select Selection.Name = “Data1” Range(Range(“E1”), Range(“E1”).End(xlDown)).Select ‘Set newrange = Range(ActiveCell, ActiveCell.End(xlDown)) ‘newrange.Select Selection.Name = “Bins1” Set FrequencyArray = Worksheets(wsC).Range(Cells(1, 6), Cells(20, 6)) FrequencyArray.FormulaArray = “=frequency(Data1,Bins1)” End Sub