(vba) looping frequency function

montecarlo2012

Well-known Member
Joined
Jan 26, 2011
Messages
984
Office Version
  1. 2010
Platform
  1. Windows
Hi every one

A picture isworth a thousand words, agree, I upload a picture .
[image missing]

I am in the chapter of LOOPS, but I don’t see what I really need.

How to loop the “frequency function” in VBA; I didn’t see nothing like that anywhere, I have and array and I would like to have frequency result at least in three different ranges, an get three different tables.

Please check my picture, maybe I make clear the point, otherwise, of course, askme; I know you can help me If I really help. (this is for self-study purpose, please I rather a code than a formula, if you don't mind, thanks). by the way, how to upload my file!!. I don't see the buttom. sorry.


Thanks.
 
Last edited by a moderator:

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Really, I have little to no idea of just what you want. And after looking at your pics was unable to achieve revelation.

However, just for interest, your 3rd pic with 0,1,2,3 in F1, G1, H1 and I1, and "this is the bin organize according to the results" in a box - if you want to get that from the material in Cols 1,2 and 3, you could try the following vba code:
Code:
Sub zem() 
Dim a(), b()
Dim c As Object, d, e
Dim i&, n&
Set c = CreateObject("scripting.dictionary")
e = Range("A1").CurrentRegion.Resize(, 3)
n = UBound(e, 1)
For i = 2 To n
    d = e(i, 3)
    If Not c.Exists(d) Then
        c(d) = c.Count + 1
        ReDim Preserve b(1 To c(d))
        ReDim Preserve a(1 To n, 1 To c(d))
        b(c(d)) = 2
        a(1, c(d)) = e(i, 3)
        a(2, c(d)) = e(i, 2)
    Else
        b(c(d)) = b(c(d)) + 1
        a(b(c(d)), c(d)) = e(i, 2)
    End If
Next i
With Range("F1").Resize(n, c.Count)
    .Value = a
    .Sort .Rows(1), Orientation:=xlLeftToRight, Header:=xlNo
    .Rows(1).Font.Bold = True
End With

End Sub
 
Upvote 0
after looking at your pics was unable to achieve revelation.

I really appreciate your reply, I understand your code, is to show the results in a bell curve style, I think you wash the pic I posted for different reason, I would like to upload my pic directly here, (I don't know how). any way here is my real question.
ABCDEFGHIJKLMNOPQrange[4-6]ST
1[1][2][3][4][5][6]binrange[3-5]range[4-6]range[5-7]range[6-8]
2741912310346
3118673421322
47121224632110
5757113443223
612216151110
7410717662222
8414191174342
910512211281000
10871177190001
1195510117100011
129125282112111
136108871122200
1481222104
151118122
163173129
172789128
18610841212
1999871210
2051111139
219512713
221218711
233312521

column"Q" results offrequencyof the rows [3]11-8-6-7-3-4[4]7-12-12-2-4-

[5]7-5-7-11-3-4 , column"R" results of frequencyof the rows[4]7-12-12-2-4-6[5]7-5-7-11-3-4[6]1-2-2-1-6-1 I think now you will see what picture I am talking about, again thanks for your reply, hope to read from you soon.
 
Last edited by a moderator:
Upvote 0
Assuming you want the Frequency of the the Numbers in column "P" based on row 1 columns "Q to T".
Try this:-
NB:- See Comment in code for Range selections Ref columns "Q to T"

VBA Code:
Sub MG15Nov23
Dim Rws         As Variant
Dim Ac          As Integer
Dim Rng         As Range
Dim Dn          As Range
Set Rng = Range(Range("P2"), Range("P" & Rows.Count).End(xlUp))


'Change the row below to the ranges you want to consider !!!
Rws = Array("C3:H5", "C4:H6", "C5:H7", "C6:H8")


For Each Dn In Rng
        For Ac = 0 To UBound(Rws)
            Dn.Offset(, Ac + 1) = Application.CountIf(Range(Rws(Ac)), Dn)
        Next Ac
Next Dn
End Sub

Regards Mick
 
Last edited by a moderator:
Upvote 0
Solution
Regards Mick
Thank you MickG, you are the best.
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,221,497
Messages
6,160,152
Members
451,625
Latest member
sukhman

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