Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sub FindFrequency()
'Update 20140326
Dim Rng As Range
Dim WorkRng As Range
Set dic = CreateObject("scripting.dictionary")
On Error Resume Next
xTitleId = "Hoc Excel Online"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
xMax = 0
xOutValue = ""
For Each Rng In WorkRng
xValue = Rng.Value
If xValue <> "" Then
dic(xValue) = dic(xValue) + 1
xCount = dic(xValue)
If xCount > xMax Then
xMax = xCount
xOutValue = xValue
End If
End If
Next
MsgBox "The most common value is: " & xOutValue & " Appeared " & xMax & " Times"
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment