VBA Function Find Freq Max

Stephen_IV

Well-known Member
Joined
Mar 17, 2003
Messages
988
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Good afternoon,
I have a function that someone gave me, it looks for the most names that occur in a row or column. It works fine except when there's a tie. In the example below Mary and Jean occur 6 times. I would like to output to show
Mary, Jean
Any help would be appreciated.


VBA Multi Max Dictionary.xlsm
A
1AL
2Joe
3Mary
4Jean
5Jack
6Mary
7Mary
8John
9Jean
10Jean
11AL
12Joe
13Mary
14Jean
15Jack
16Mary
17Mary
18John
19Jean
20Jean
Sheet2




VBA Code:
Function FreqMax(r As Range)
Set dic = CreateObject("scripting.dictionary")
On Error Resume Next
Mmax = 0
x = ""
    For Each xcell In r
        If xcell.Value <> "" Then
            dic(xcell.Value) = dic(xcell.Value) + 1
            If dic(xcell.Value) > Mmax Then
                Mmax = dic(xcell.Value)
                x = xcell.Value
            End If
        End If
    Next
FreqMax = x
End Function
 

Some videos you may like

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,526
Office Version
  1. 365
Platform
  1. Windows
Hi what version of Excel are you using?
I suggest that you update your Account details (click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 

Stephen_IV

Well-known Member
Joined
Mar 17, 2003
Messages
988
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi what version of Excel are you using?
I suggest that you update your Account details (click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
Sorry about that, I updated the info.
 

Bo_Ry

Board Regular
Joined
Oct 27, 2018
Messages
142
Office Version
  1. 365
Platform
  1. Windows
Please try

Array formula for a single column.
=TEXTJOIN(", ",,INDEX(A1:A20,MODE.MULT(MATCH(A1:A20,A1:A20,))))

or UDF

VBA Code:
Function FreqMax(r As Range)
Dim rn As Range, dic As Object, mx As Long, a, t As String
Set dic = CreateObject("scripting.dictionary")
    For Each rn In r
        If rn <> "" Then
            dic(rn.Value) = dic(rn.Value) + 1
            mx = Application.Max(dic(rn.Value), mx)
        End If
    Next
    For Each a In dic.keys
        If dic(a) = mx Then t = t & ", " & a
    Next
FreqMax = Mid(t, 3)
End Function


Book1
ABCD
1ALALMary, Jean
2JoeJoeMary, Jean
3MaryMary
4JeanJeanMary, Jean
5JackJack
6MaryMary
7MaryMary
8JohnJohn
9JeanJean
10JeanJean
11AL
12Joe
13Mary
14Jean
15Jack
16Mary
17Mary
18John
19Jean
20Jean
Sheet1
Cell Formulas
RangeFormula
D1D1=TEXTJOIN(", ",,INDEX(A1:A20,N(IF(1,MODE.MULT(MATCH(A1:A20,A1:A20,))))))
D2D2=TEXTJOIN(", ",,INDEX(A1:A20,MODE.MULT(MATCH(A1:A20,A1:A20,))))
D4D4=FreqMax(A1:B20)
 

Stephen_IV

Well-known Member
Joined
Mar 17, 2003
Messages
988
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Beautiful!!! Thank you very much! I really appreciate it!!!!
 

Watch MrExcel Video

Forum statistics

Threads
1,127,524
Messages
5,625,309
Members
416,092
Latest member
dodovisk

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
Top