Hi,
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com
ffice
ffice" /><o
></o
>
I have numerical data in a column. I need to use the frequency function on it and to display the BinArray and the result of the frequency function on a new sheet.
The bit of code below generates the BinArray and the DataArray using variables inputed by the user.
One of my question is, if I try to declare the type of the FreqArray to anything else than Variant, I got an error message however the output of the frequency function cannot be anything else then an array of integers.
'CALC number of elements in the BinArray and files up the array with the elements
Dim NOE As Integer 'NOE = number of elements
NOE = 2 * MaxBin / BinWidth + 1
Dim BinArray() As Integer
ReDim BinArray(1 To NOE)
Dim intI As Integer
Dim BinElement As Integer
BinElement = MaxBin
For intI = 1 To NOE
BinArray(intI) = BinElement
BinElement = BinElement - BinWidth
Next
'Generates the DataArray
Dim DataArray As Variant
With acs
DataArray = .Range(.Cells(FirstRow, FLCol), .Cells(LastRow, FLCol)).Value
End With
Dim FreqArray() As Variant
ReDim FreqArray(1 To NOE)
FreqArray = Application.WorksheetFunction.frequency(DataArray, BinArray)
'INSERT DATA WORKSHEET
Dim acwb As Workbook
Set acwb = ActiveWorkbook
acwb.Worksheets.Add
My second question is:
I try display the result of the frequency function and the BinArray on the new sheet with the code below:
'WRITES BinArray and FreqArray into the new sheet
Dim ciBin As String
ciBin = "A"
Dim riBinF As Integer 'Row Index Bin First
riBinF = 2
Dim riBinL As Integer 'Row Index Bin Last
riBinL = riBinF + NOE
Range(ciBin & riBinF, ciBin & riBinL) = Application.WorksheetFunction.Transpose(BinArray)
'WRITES FREQ VALUES into Data sheet
ciBin = "B"
Range(ciBin & riBinF, ciBin & riBinL) = Application.WorksheetFunction.Transpose(FreqArray)
The BinArray displayed correctly but I have zeros instead of the frequency values in the cells, meanwhile I can see in the locals window that the correct frequency values are in the FreqArray.
Many thanks in advance!
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com
I have numerical data in a column. I need to use the frequency function on it and to display the BinArray and the result of the frequency function on a new sheet.
The bit of code below generates the BinArray and the DataArray using variables inputed by the user.
One of my question is, if I try to declare the type of the FreqArray to anything else than Variant, I got an error message however the output of the frequency function cannot be anything else then an array of integers.
'CALC number of elements in the BinArray and files up the array with the elements
Dim NOE As Integer 'NOE = number of elements
NOE = 2 * MaxBin / BinWidth + 1
Dim BinArray() As Integer
ReDim BinArray(1 To NOE)
Dim intI As Integer
Dim BinElement As Integer
BinElement = MaxBin
For intI = 1 To NOE
BinArray(intI) = BinElement
BinElement = BinElement - BinWidth
Next
'Generates the DataArray
Dim DataArray As Variant
With acs
DataArray = .Range(.Cells(FirstRow, FLCol), .Cells(LastRow, FLCol)).Value
End With
Dim FreqArray() As Variant
ReDim FreqArray(1 To NOE)
FreqArray = Application.WorksheetFunction.frequency(DataArray, BinArray)
'INSERT DATA WORKSHEET
Dim acwb As Workbook
Set acwb = ActiveWorkbook
acwb.Worksheets.Add
My second question is:
I try display the result of the frequency function and the BinArray on the new sheet with the code below:
'WRITES BinArray and FreqArray into the new sheet
Dim ciBin As String
ciBin = "A"
Dim riBinF As Integer 'Row Index Bin First
riBinF = 2
Dim riBinL As Integer 'Row Index Bin Last
riBinL = riBinF + NOE
Range(ciBin & riBinF, ciBin & riBinL) = Application.WorksheetFunction.Transpose(BinArray)
'WRITES FREQ VALUES into Data sheet
ciBin = "B"
Range(ciBin & riBinF, ciBin & riBinL) = Application.WorksheetFunction.Transpose(FreqArray)
The BinArray displayed correctly but I have zeros instead of the frequency values in the cells, meanwhile I can see in the locals window that the correct frequency values are in the FreqArray.
Many thanks in advance!