LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Using Find as lookup method goes to semi endless loop

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
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find Method vs. For...Next Loop mikelee101[_2_] Excel Programming 3 July 10th 08 09:43 PM
Find Method in For Loop Sisilla[_2_] Excel Programming 3 May 3rd 07 08:02 PM
Endless loop freddie mac Excel Programming 2 August 1st 06 03:19 PM
endless loop help John Excel Programming 1 October 26th 05 04:51 PM
Endless loop? John Excel Programming 24 August 2nd 05 06:41 PM


All times are GMT +1. The time now is 06:41 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"