L
L. Howard
I wrote code to find these array elements if they are single strings in a cell and highlights them. It works well.
I am trying to adjust that code to highlight the elements if they are used in a sentence... "I like beer." or just 'beer' alone then it would be highlighted.
This code comes up "No match found." and I have to hold esc key for about 500? iterations then the first occurance only of any found elements are highlighted.
I'm thinking xlPart may be a problem also, but havn't got that far with the code yet.
Thanks.
Howard
Sub MyBadFoodFind()
Dim i As Long
Dim MyArr As Variant
Dim c As Range
Sheets("Sheet1").Cells.Interior.ColorIndex = xlNone
Dim iRet As Integer
Dim strPrompt As String
Dim strTitle As String
strPrompt = " Highlights have been removed." & vbCr & _
"If you want to continue click ""Yes."""
strTitle = "My Bad Eats"
iRet = MsgBox(strPrompt, vbYesNo, strTitle)
If iRet = vbNo Then
Exit Sub
Else
'
End If
MyArr = Array("milk", "soda", "fries", "pizza", "beer", "chips", _
"candy", "alcohol", "mcdonalds", "wendys", "burger king")
Application.ScreenUpdating = False
For Each c In Sheets("Sheet1").UsedRange
For i = LBound(MyArr) To UBound(MyArr)
Set c = Sheets("Sheet1").UsedRange.Find(What:=MyArr(i), _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not c Is Nothing Then
c.Interior.ColorIndex = 6
Else
MsgBox "No match found."
End If
Next 'i
Next 'c
Application.ScreenUpdating = True
End Sub
I am trying to adjust that code to highlight the elements if they are used in a sentence... "I like beer." or just 'beer' alone then it would be highlighted.
This code comes up "No match found." and I have to hold esc key for about 500? iterations then the first occurance only of any found elements are highlighted.
I'm thinking xlPart may be a problem also, but havn't got that far with the code yet.
Thanks.
Howard
Sub MyBadFoodFind()
Dim i As Long
Dim MyArr As Variant
Dim c As Range
Sheets("Sheet1").Cells.Interior.ColorIndex = xlNone
Dim iRet As Integer
Dim strPrompt As String
Dim strTitle As String
strPrompt = " Highlights have been removed." & vbCr & _
"If you want to continue click ""Yes."""
strTitle = "My Bad Eats"
iRet = MsgBox(strPrompt, vbYesNo, strTitle)
If iRet = vbNo Then
Exit Sub
Else
'
End If
MyArr = Array("milk", "soda", "fries", "pizza", "beer", "chips", _
"candy", "alcohol", "mcdonalds", "wendys", "burger king")
Application.ScreenUpdating = False
For Each c In Sheets("Sheet1").UsedRange
For i = LBound(MyArr) To UBound(MyArr)
Set c = Sheets("Sheet1").UsedRange.Find(What:=MyArr(i), _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not c Is Nothing Then
c.Interior.ColorIndex = 6
Else
MsgBox "No match found."
End If
Next 'i
Next 'c
Application.ScreenUpdating = True
End Sub