Frequency on VBA in a different array arranging

montecarlo2012

Well-known Member
Joined
Jan 26, 2011
Messages
984
Office Version
  1. 2010
Platform
  1. Windows
Hello everyone.
I understand the Frequency function require an array like multiplication model,
but, in my case at the moment I have different needs
Please check this out

MR EXCEL.xls
BCDEF
1
21418252729
31518222434
449343536
556151933
61321283132
723222325
813102030
918152227
Sheet1


in this case what I really need is the frequency of 36 cells and not the frequency of the array 7 * 5
so my question is
how to do that on vba
in my minisheet the regular use of frequency will be (B2:F8)
but, is not what I need, would be B2:F8 plus B8

in other words how to choose any range but not necessarily a perfect array.
thank you for reading this.

I upload the images because the xx2 do not show the formatting that illustrate the idea
1684169541251.png

so I need the frequency of the cells with the borders only.
 
Last edited:

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
=FREQUENCY(B2:F8*B9,P2:P37)

in this way accept the extra cell, but do not count anything,
somebody maybe can tell me about
SUMIF, or COUNTIF, ||"any formula "|| that work in cases where a perfect array is not part of the problem
thanks
 
Upvote 0
at least this formula take the cells I want,
1684179594958.png

but the output is all = "0" so help need it
 
Upvote 0
Hi, the rate of views/answers make me think, that maybe excel itself is not build to answer this kind of questions, in other words everything has to be linear or square or rectangular, other wise
is not possible to answer.
Plus the people read 2 answers and is not, is a comments from myself, so if somebody want to help base on that info, then I don't get help.
thank you for reading this.
 
Upvote 0
=FREQUENCY(B2:F8*B9,P2:P37)

in this way accept the extra cell, but do not count anything,
somebody maybe can tell me about
SUMIF, or COUNTIF, ||"any formula "|| that work in cases where a perfect array is not part of the problem
thanks
What is in P2:P37? If they are blank, Frequency will be 0
may be:
=FREQUENCY(B2:F8*B9,ROW(P1:P36))
with ROW(P1:P36) = {1,2,3,...,36}
But I believe the range size still be 7*2=35, not 36
 
Upvote 0
And here is UDF solution

Book2
BCDEFGP
214182527291
315182224342
4493435363
5561519334
613212831325
7232223256
8131020307
9181522278
109
1110
122=freq(P2:P37,B2:F8,B9)11
1312
1413
1514
1615
1716
1817
1918
2019
2120
2221
2322
2423
2524
2625
2726
2827
2928
3029
3130
3231
3332
3433
3534
3635
3736
Sheet1
Cell Formulas
RangeFormula
B12B12=freq(P2:P37,B2:F8,B9)
P3:P37P3=P2+1


VBA Code:
Option Explicit
Function freq(binRange As Range, dataRange1 As Range, Optional dataRange2 As Range) As Variant
    Dim i As Long, ii As Long, j As Long
    Dim freq1(), dataV1, dataV2, binV
    On Error Resume Next
    ' Convert data range and bin range to arrays
    dataV1 = dataRange1.Value
    dataV2 = dataRange2.Value
    binV = binRange.Value
    
    ' Initialize the frequency array
    ReDim freq1(1 To UBound(binV) - 1, 1 To 1)
    
    ' Loop through each data value 1 and count frequencies
    For i = 1 To UBound(dataV1)
        For ii = 1 To UBound(dataV1, 2)
            If IsNumeric(dataV1(i, ii)) Then
                For j = 1 To UBound(binV) - 1
                    If dataV1(i, ii) >= binV(j, 1) And dataV1(i, ii) < binV(j + 1, 1) Then
                        freq1(j, 1) = freq1(j, 1) + 1
                        Exit For
                    End If
                Next
            End If
        Next
    Next
    
    ' Loop through each data value 2 and count frequencies
    For i = 1 To UBound(dataV2)
        For ii = 1 To UBound(dataV2, 2)
            If IsNumeric(dataV2(i, ii)) Then
                For j = 1 To UBound(binV) - 1
                    If dataV2(i, ii) >= binV(j, 1) And dataV2(i, ii) < binV(j + 1, 1) Then
                        freq1(j, 1) = freq1(j, 1) + 1
                        Exit For
                    End If
                Next
            End If
        Next
    Next
    ' Return the frequency array
    freq = freq1
End Function
 
Upvote 1
Solution
What is in P2:P37? If they are blank, Frequency will be 0
may be:
on P2:P37 is the array of numbers from 1:36
 
Upvote 0

Forum statistics

Threads
1,215,324
Messages
6,124,250
Members
449,149
Latest member
mwdbActuary

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