Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 126
Default Stopping looped "Find" command

Hi

I have the following Excel problem.

I have the following details in a column.

teka sfffss
fhhr teka
25 teka

I used the following looped 'find' command to make all of them 'teka'.


Cells(1, 1).Select

Do
Cells.Find(What:="teka", After:=ActiveCell, LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell = "teka"
Loop Until Not ActiveCell.FormulaR1C1 = "teka"
End Sub

The problem is the above one is an infinite loop. How to stop it ? If I am
to use error handler how to use it more once in one macro?

Thanks

Varne




  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,939
Default Stopping looped "Find" command

Try something like this...

Sub test()
Dim rngFound As Range
Dim strFirstAddress As String

Set rngFound = Cells.Find(What:="teka", _
LookAt:=xlPart, _
LookIn:=xlFormulas, _
MatchCase:=False)
If rngFound Is Nothing Then
MsgBox "Teka was not found"
Else
strFirstAddress = rngFound.Address
Do
rngFound.Value = "teka"
Set rngFound = Cells.FindNext(rngFound)
Loop Until rngFound.Address = strFirstAddress

End If
End Sub

--
HTH...

Jim Thomlinson


"Varne" wrote:

Hi

I have the following Excel problem.

I have the following details in a column.

teka sfffss
fhhr teka
25 teka

I used the following looped 'find' command to make all of them 'teka'.


Cells(1, 1).Select

Do
Cells.Find(What:="teka", After:=ActiveCell, LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell = "teka"
Loop Until Not ActiveCell.FormulaR1C1 = "teka"
End Sub

The problem is the above one is an infinite loop. How to stop it ? If I am
to use error handler how to use it more once in one macro?

Thanks

Varne




  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 389
Default Stopping looped "Find" command

Or the non-looping way:

Cells.Replace What:="*teka*", Replacement:="teka", LookAt:=xlPart,
MatchCase:=False


"Varne" wrote in message
...
Hi

I have the following Excel problem.

I have the following details in a column.

teka sfffss
fhhr teka
25 teka

I used the following looped 'find' command to make all of them 'teka'.


Cells(1, 1).Select

Do
Cells.Find(What:="teka", After:=ActiveCell, LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell = "teka"
Loop Until Not ActiveCell.FormulaR1C1 = "teka"
End Sub

The problem is the above one is an infinite loop. How to stop it ? If I am
to use error handler how to use it more once in one macro?

Thanks

Varne






  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 126
Default Stopping looped "Find" command

Hi Jim

Your codes do the job. Thanks.

Varne

"Jim Thomlinson" wrote:

Try something like this...

Sub test()
Dim rngFound As Range
Dim strFirstAddress As String

Set rngFound = Cells.Find(What:="teka", _
LookAt:=xlPart, _
LookIn:=xlFormulas, _
MatchCase:=False)
If rngFound Is Nothing Then
MsgBox "Teka was not found"
Else
strFirstAddress = rngFound.Address
Do
rngFound.Value = "teka"
Set rngFound = Cells.FindNext(rngFound)
Loop Until rngFound.Address = strFirstAddress

End If
End Sub

--
HTH...

Jim Thomlinson


"Varne" wrote:

Hi

I have the following Excel problem.

I have the following details in a column.

teka sfffss
fhhr teka
25 teka

I used the following looped 'find' command to make all of them 'teka'.


Cells(1, 1).Select

Do
Cells.Find(What:="teka", After:=ActiveCell, LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell = "teka"
Loop Until Not ActiveCell.FormulaR1C1 = "teka"
End Sub

The problem is the above one is an infinite loop. How to stop it ? If I am
to use error handler how to use it more once in one macro?

Thanks

Varne




Reply
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
Stopping "Query Refresh" messages fmistry Excel Discussion (Misc queries) 2 March 6th 07 03:38 PM
How to cancel a find & replace command "midstream"? Matt from GVA Excel Worksheet Functions 4 September 4th 06 05:47 PM
Stopping the "This removes the subtotal and sorts again." notifica Hoppy Excel Discussion (Misc queries) 1 August 3rd 06 08:55 PM
HELP on "left","right","find","len","substitute" functions serene83 Excel Discussion (Misc queries) 5 June 27th 06 02:23 AM
inserting a conditional "go to" command on a excel "if" function velasques Excel Worksheet Functions 5 March 10th 06 08:16 PM


All times are GMT +1. The time now is 10:23 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"