gpt4 book ai didi

excel - 范围内最常见的单词,忽略空格

转载 作者:行者123 更新时间:2023-12-02 15:22:42 25 4
gpt4 key购买 nike

我目前使用以下公式来查找范围内最常见的单词或数字:

=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 键。

这是一个例子:

sdfgh

关于excel - 范围内最常见的单词,忽略空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26868704/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com