匹配string中的完整单词

我有下面的代码填充偏移单元格与服务应符合条件。 然而在这个阶段,它是在string出现在单元格内的基础上运行的,它将应用这个值而不是一个完整的单词。 例如,在我的标准中,我有“访问”,当不应该的时候,“Vistor”(在一个单元格内)将遵守我的代码。 请有人协助?

Option Compare Text Sub CHECK_CELL_VALUES() Dim LASTROW As Long Application.ScreenUpdating = False With Sheet1 LASTROW = .Range("A1048576").End(xlUp).Row For i = 2 To LASTROW If Cells(i, 7).Value Like "*Service*" _ Or Cells(i, 7).Value Like "*Servicing*" _ Or Cells(i, 7).Value Like "* Labour*" _ Or Cells(i, 7).Value Like "* Job*" _ Or Cells(i, 7).Value Like "* Hire*" _ Or Cells(i, 7).Value Like "* Visit*" _ Or Cells(i, 7).Value Like "* Scaffold*" _ Or Cells(i, 7).Value Like "* Contract*" _ Or Cells(i, 7).Value Like "* Hour*" _ Or Cells(i, 7).Value Like "* Month*" _ Or Cells(i, 7).Value Like "* Quarter*" _ Or Cells(i, 7).Value Like "* Day*" _ Or Cells(i, 7).Value Like "* Maintenance*" _ Or Cells(i, 7).Value Like "* Repair*" _ Or Cells(i, 7).Value Like "* Survey*" _ Or Cells(i, 7).Value Like "* Training*" _ Or Cells(i, 7).Value Like "* Calibration*" _ Then Cells(i, 7).Offset(0, 46).Value = "Service" Debug.Print Cells(i, 7).Address Next i End With Application.ScreenUpdating = True End Sub 

我这样做的方法是:a)在要search的string前后添加空格b)search前后添加空格的string。 这里是一个search单词VISIT的例子,它将匹配“访问”,“访问”,“访问某些事物”,但不包括“访问者”

 InStr(1, " " & UCase(Sheets("Sheet1").Cells(i, 1)) & " ", " VISIT ") 

尝试改变这一点:

 If Cells(i, 7).Value Like "*Service*" 

对此:

 If InStr(Cells(i,7).Value,"Service") > 0 

等等等等 – 这将匹配整个string"Service"更多关于InStr信息可以在这里find