use of frequency function - display arrays

jazztech

Board Regular
Joined
Aug 31, 2007
Messages
119
Hi,
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
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!
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Surely the result would be a vertical array anyway, so why transpose? Maybe that's your problem.
 
Upvote 0
Hi Glenn,

Thank you for your reply. Someone else also just pointed out the differences between the def array layout and the output of the frequency function. I need to catch up with very fundamental bits.

Thanks!
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,485
Members
448,967
Latest member
visheshkotha

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top