Created
July 22, 2017 13:58
-
-
Save ndthanh/96ad3b7fb6d50d2315ca1bb7996b63d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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