我目前使用以下公式查找范围内最常见的单词或数字:
=INDEX(E9:E18,MODE(MATCH(E9:E18,E9:E18,0)))
但是,如果有任何空白单元格,则公式将返回空白单元格作为模式。我该如何修改它以找到最常见的单词/数字而忽略任何空白单元格?
非常感谢
尝试以下用户定义的功能:
Public Function MostFreq(rIn As Range) As Variant
Dim c As Collection, r As Range, N As Long, How()
Dim cc As Long, wf As WorksheetFunction
Dim i As Long, Biggest As Long
Set c = New Collection
Set wf = Application.WorksheetFunction
On Error Resume Next
For Each r In rIn
v = r.Text
If v <> "" Then
c.Add v, CStr(v)
End If
Next r
On Error GoTo 0
cc = c.Count
ReDim How(1 To cc)
For i = 1 To cc
How(i) = wf.CountIf(rIn, c.Item(i))
Next i
Biggest = wf.Max(How)
For i = 1 To cc
If How(i) = Biggest Then
MostFreq = c.Item(i)
End If
Next i
End Function
为了避免VBA,选择一个单元格(例如A1)并输入数组公式:
=INDEX(E9:E18,MODE(IF((E9:E18<>"")*ISNA(MATCH(E9:E18,$B$1:$B1,0)),MATCH(E9:E18,E9:E18,0))))
数组公式必须使用Ctrl + Shift + Enter输入,而不仅仅是Enter键。
这里是一个例子:
我有18000行和7列数据。我使用了7列的公式。
= INDEX(E9:E18,MODE(IF((E9:E18 <>“”)* ISNA(MATCH(E9:E18,$ B $ 1:$ B1,0)),MATCH(E9:E18,E9: E18,0))))..]
有时我们在一个单元格(7列)中只有1个数字或文本。我如何修改它以找到忽略6个空白单元格的唯一单词/数字?