如何查找在单元格中多次使用的所有文本列表

问题描述 投票:-1回答:1

我试图找到我在单元格中多次使用的所有文本列表。

例:

我的名字是Ayesha Akter和Sumon是我的男朋友。 Sumon叫我Ayesha。

结果将是:

我的Ayesha |是

我尝试使用String&Substring但是,它只显示了我给substring的一些特定文本的结果。这是我试过的公式。

=IF(ISNUMBER(SEARCH($B$1,$A2)),$B$1,"")
excel excel-vba excel-formula vba
1个回答
0
投票

试试这个代码

Sub Test()
Dim e           As Variant
Dim nStr        As String
Dim txt         As String
Dim r           As Long

For r = 1 To Cells(Rows.Count, 1).End(xlUp).Row
    If Cells(r, 1).Value = "" Then Cells(r, 2).Value = ""
    nStr = Replace(Cells(r, 1).Value, ".", ""): txt = ""

    With CreateObject("Scripting.Dictionary")
        .CompareMode = 1
        For Each e In Split(nStr, " ")
            .Item(Trim$(e)) = .Item(Trim$(e)) + 1
        Next e
        For Each e In .keys
            If .Item(e) > 1 Then
                txt = txt & " | " & e
            End If
        Next e
    End With

    Cells(r, 2).Value = Mid$(txt, 3)
Next r
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.