如何查找在单元格中多次使用的所有文本列表
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何查找在单元格中多次使用的所有文本列表相关的知识,希望对你有一定的参考价值。
我试图找到我在单元格中多次使用的所有文本列表。
例:
我的名字是Ayesha Akter和Sumon是我的男朋友。 Sumon叫我Ayesha。
结果将是:
我的Ayesha |是
我尝试使用String&Substring但是,它只显示了我给substring的一些特定文本的结果。这是我试过的公式。
=IF(ISNUMBER(SEARCH($B$1,$A2)),$B$1,"")
答案
试试这个代码
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
以上是关于如何查找在单元格中多次使用的所有文本列表的主要内容,如果未能解决你的问题,请参考以下文章
查找和替换替代方法?而不是 "REPLACE",只是简单地添加文本到现有的单元格中?