montecarlo2012
Well-known Member
- Joined
- Jan 26, 2011
- Messages
- 986
- Office Version
- 2010
- Platform
- Windows
Hi all.
this code let me see the frequency of random numbers on column H and display anywhere
My problem now is I tried to do the same in a row, then do not work at all.
I would like to be able to change the input boxes, instead, would be nice if work for B2 to the last column and display results on A92
as a reference this is a images of the frequency result accomplish for this code
this code read column H and whatever found, regroup by frequency,
but now I need row B.
thanks for reading this
I would like to hear from you.
VBA Code:
Sub Freq_Ran()
Dim freqs(), xxx As Range
Set xxx = Application.InputBox("Select the cell you want to process", "Location of souce data", Default:="$H$2:$H$2800", Type:=8)
''' I would like not to use inputbox instead just search for B2 to the last row
vals = xxx.Value
vmax = Application.Max(vals)
vmin = Application.Min(vals)
bin = Evaluate("row(A" & vmin & ":A" & vmax & ")")
freqs = Application.WorksheetFunction.FREQUENCY(vals, bin)
ReDim Preserve freqs(1 To UBound(freqs), 1 To 2)
For i = 1 To UBound(bin)
freqs(i, 2) = bin(i, 1)
Next i
For i = 2 To UBound(bin)
For j = UBound(bin) To i Step -1
If freqs(j, 1) < freqs(j - 1, 1) Then
temp1 = freqs(j, 1): temp2 = freqs(j, 2)
freqs(j, 1) = freqs(j - 1, 1): freqs(j, 2) = freqs(j - 1, 2)
freqs(j - 1, 1) = temp1: freqs(j - 1, 2) = temp2
End If
Next j
Next i
'determine size of array:
i = 1
ColCount = 0
Do
myMax = 1
ColCount = ColCount + 1
Do
i = i + 1
myMax = myMax + 1
Loop Until freqs(i, 1) <> freqs(i - 1, 1)
If myMax > Max Then Max = myMax
Loop Until i >= UBound(bin)
Dim Results()
ReDim Results(1 To Max, 1 To ColCount + 1)
i = 1: c = 1
Do
r = 1
Results(r, c) = freqs(i, 1)
r = r + 1
Do
Results(r, c) = freqs(i, 2)
r = r + 1
i = i + 1
Loop Until freqs(i, 1) <> freqs(i - 1, 1)
c = c + 1
Loop Until i > UBound(bin)
Dim Destn As Range
Set Destn = Application.InputBox("Select the cell where do you want the results", "Location of result table", Type:=8)
'instead I would like to display directly on A92
Destn.Resize(UBound(Results), UBound(Results, 2)).Value = Results
Application.Goto Destn
End Sub
My problem now is I tried to do the same in a row, then do not work at all.
I would like to be able to change the input boxes, instead, would be nice if work for B2 to the last column and display results on A92
as a reference this is a images of the frequency result accomplish for this code
this code read column H and whatever found, regroup by frequency,
but now I need row B.
thanks for reading this
I would like to hear from you.