我在下面有这段代码非常接近我想要做的。它的工作原理是您按下 Excel 电子表格中的“列出单词问题”按钮,它会逐个单元格地扫描 A 列中的所有文本,并针对包含单词列表的单独工作表进行扫描。如果存在匹配项(在第 1 列中每个单独单元格中的内容之间),则它将匹配的单词放入 b 列中的相邻行中。
这里(http://mintywhite.com/more/software-more/microsoft-excel-analyze-free-text-surveys-feedback-complaints-part-2)是我找到代码的文章的链接和链接 ( http://mintywhite.com/wp-content/uploads/2011/02/wordcount2.xls ) 下载整个 .xls 电子表格。
我正在寻找的是一个简单的更改,因此除非该单词在第一个工作表的 A 列的每个单元格/行中出现至少 5 次,否则不会有“匹配”。
Sub WordCount()
Dim vArray, WordIssue, ElementCounter As Variant
Dim lngLoop, lngLastRow As Long
Dim rngCell, rngStoplist As Range
ElementCounter = 2 'setting a default value for the counter
Worksheets(1).Activate
For Each rngCell In Worksheets("Word").Range("A3", Cells(Rows.Count, "A").End(xlUp))
vArray = Split(rngCell.Value, " ") 'spliting the value when there is a space
vrWordIssue = ""
ElementCounter = ElementCounter + 1 'increases the counter every loop
For lngLoop = LBound(vArray) To UBound(vArray)
If Application.WorksheetFunction.CountIf(Sheets("Issue").Range("A2:A" & Sheets("Issue").UsedRange.Rows.Count), vArray(lngLoop)) > 0 Then 'this is to test if the word exist in the Issue Sheet.
If vrWordIssue = "" Then
vrWordIssue = vArray(lngLoop) 'assigning the word
Else
If InStr(1, vrWordIssue, vArray(lngLoop)) = 0 Then 'a binary of comparison
vrWordIssue = vrWordIssue & ", " & vArray(lngLoop) 'this will concatinate words issue that exist in Issue Sheet
End If
End If
End If
Next lngLoop
Worksheets("Word").Range("B" & ElementCounter).Value = vrWordIssue 'entering the final word issue list into cell.
Next rngCell
End Sub