这将循环遍历单元格并比较两个字符串,将 B 中的所有逗号分隔列表拆分为一个数组,并将元素与 A 进行比较。
Dim i As Long
Dim lr As Long
Dim wordarr As Variant
Dim element As Variant
Dim target As Long
With Sheets(1)
lr = .Cells(.Rows.Count, 1).End(xlUp).Row
For i = 2 To lr
If InStr(1, .Cells(i, 2).Value, ",") Then
wordarr = Split(.Cells(i, 2).Value, ",")
For Each element In wordarr
target = InStr(1, .Cells(i, 1).Value, element)
If target > 0 Then
.Cells(i, 1).Characters(target, Len(element)).Font.Color = RGB(255, 0, 0)
End If
Next
Else
target = InStr(1, .Cells(i, 1).Value, .Cells(i, 2).Value)
If target > 0 Then
.Cells(i, 1).Characters(target, Len(.Cells(i, 2).Value)).Font.Color = RGB(255, 0, 0)
End If
End If
Next i
End With