Excel VBA 如果 cell.Value =... 那么

Ker*_*tar 5 excel vba

我有这个运行良好的代码:

Sub colortest()
Dim cell As Range
For Each cell In Range("Range1")
If cell.Value = "Word1" Then
cell.Interior.Color = XlRgbColor.rgbLightGreen
ElseIf cell.Value = "Word2" Then
cell.Interior.Color = XlRgbColor.rgbOrange
ElseIf cell.Value = "Word3" Then
cell.Interior.Color = XlRgbColor.rgbRed
End If
Next cell
End Sub
Run Code Online (Sandbox Code Playgroud)

我的问题是这些值仅在单元格仅包含该文本时才起作用。但是我的单元格通常是这样的:“Something, 10254, 15/15, Word1 Another Word” 我只需要Word1。谢谢,