'不神奇就是按这要求来写的。看来问题搞定了,那就贴代码了,因为这代码还有点通用,如果谁遇到了类似的问题稍作修改就能用
Option Explicit
Sub test()
Dim arr, i, j, t, dic, key, row, pos
Set dic = CreateObject("scripting.dictionary")
row = Cells(Rows.Count, "e").End(xlUp).row
arr = Range("e6:e" & row)
For i = 1 To UBound(arr, 1)
If Len(arr(i, 1)) Then
t = Replace(arr(i, 1), Space(1), vbNullString)
t = Replace(t, ",", ",")
t = Replace(t, "'", vbNullString)
If InStr(t, ",") Then
t = Split(t, ",")
For j = 0 To UBound(t): dic(t(j)) = dic(t(j)) + 1: Next
Else
dic(t) = dic(t) + 1
End If
End If
Next
Cells(6, "e").Resize(row).Font.Color = vbBlack
For i = 6 To row
If Len(Cells(i, "e")) Then
t = Replace(Cells(i, "e").Value, Space(1), vbNullString)
t = Replace(t, ",", ",")
t = Replace(t, "'", vbNullString)
If InStr(t, ",") Then
t = Split(t, ",")
For j = 0 To UBound(t)
If dic(t(j)) > 1 Then
pos = 1
Do
pos = InStr(pos, Cells(i, "e"), t(j))
If pos > 0 Then
Cells(i, "e").Characters(pos, Len(t(j))).Font.Color = vbRed
pos = pos + 1
Else
Exit Do
End If
Loop
End If
Next
Else
If dic(t) > 1 Then Cells(i, "e").Font.Color = vbRed
End If
End If
Next
End Sub |