Skip to content

Instantly share code, notes, and snippets.

@ndthanh
Created July 22, 2017 13:58
Show Gist options
  • Save ndthanh/96ad3b7fb6d50d2315ca1bb7996b63d6 to your computer and use it in GitHub Desktop.
Save ndthanh/96ad3b7fb6d50d2315ca1bb7996b63d6 to your computer and use it in GitHub Desktop.
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