Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default loop and findnext

Can someone tell me why this won't find the next value in the loop... it
stays on the first one and crashes my excel...

heets("c").Select
Set wks = ActiveSheet
Set rngToSearch = wks.Columns(1)
Set RngFound = rngToSearch.Find(what:="new", LookIn:=xlValues,
lookat:=xlWhole)
If RngFound Is Nothing Then
MsgBox "Nothing"
Else
Do
r = RngFound.Row
Range("a" & r, "z" & r).Select
With Selection.Interior
.ColorIndex = 36
.Pattern = xlSolid
End With
Range("a" & r).Select
Set RngFound = rngToSearch.FindNext
Loop Until RngFound Is Nothing
End If
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default loop and findnext

sheets("c").Select
Set wks = ActiveSheet
Set rngToSearch = wks.Columns(1)
Set RngFound = rngToSearch.Find(what:="new", LookIn:=xlValues,
lookat:=xlWhole)
If RngFound Is Nothing Then
MsgBox "Nothing"
Else
sAddr = RngFound.Address
Do
r = RngFound.Row
Range("a" & r, "z" & r).Select
With Selection.Interior
.ColorIndex = 36
.Pattern = xlSolid
End With
Range("a" & r).Select
Set RngFound = rngToSearch.FindNext(rngFound)
Loop Until RngFound Is Nothing or RngFound.Address = _
sAddr
End If
End Sub

--
Regards,
Tom Ogilvy

"John" wrote in message
...
Can someone tell me why this won't find the next value in the loop... it
stays on the first one and crashes my excel...

heets("c").Select
Set wks = ActiveSheet
Set rngToSearch = wks.Columns(1)
Set RngFound = rngToSearch.Find(what:="new", LookIn:=xlValues,
lookat:=xlWhole)
If RngFound Is Nothing Then
MsgBox "Nothing"
Else
Do
r = RngFound.Row
Range("a" & r, "z" & r).Select
With Selection.Interior
.ColorIndex = 36
.Pattern = xlSolid
End With
Range("a" & r).Select
Set RngFound = rngToSearch.FindNext
Loop Until RngFound Is Nothing
End If
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default loop and findnext

Thank you Tom, I appreciate the help.

"Tom Ogilvy" wrote:

sheets("c").Select
Set wks = ActiveSheet
Set rngToSearch = wks.Columns(1)
Set RngFound = rngToSearch.Find(what:="new", LookIn:=xlValues,
lookat:=xlWhole)
If RngFound Is Nothing Then
MsgBox "Nothing"
Else
sAddr = RngFound.Address
Do
r = RngFound.Row
Range("a" & r, "z" & r).Select
With Selection.Interior
.ColorIndex = 36
.Pattern = xlSolid
End With
Range("a" & r).Select
Set RngFound = rngToSearch.FindNext(rngFound)
Loop Until RngFound Is Nothing or RngFound.Address = _
sAddr
End If
End Sub

--
Regards,
Tom Ogilvy

"John" wrote in message
...
Can someone tell me why this won't find the next value in the loop... it
stays on the first one and crashes my excel...

heets("c").Select
Set wks = ActiveSheet
Set rngToSearch = wks.Columns(1)
Set RngFound = rngToSearch.Find(what:="new", LookIn:=xlValues,
lookat:=xlWhole)
If RngFound Is Nothing Then
MsgBox "Nothing"
Else
Do
r = RngFound.Row
Range("a" & r, "z" & r).Select
With Selection.Interior
.ColorIndex = 36
.Pattern = xlSolid
End With
Range("a" & r).Select
Set RngFound = rngToSearch.FindNext
Loop Until RngFound Is Nothing
End If
End Sub




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default loop and findnext

hi,
i copied your code and tried to run it. got caught in an endless loop. so i
re-wrote i a little. your main problem was in the do loop.

Sub macfindit()
Dim wks As Worksheet
Dim rngToSearch As Range
Dim rngFound As Range
Dim r As Long
Dim addr As String

'Sheets("Sheet1").Select
Set wks = ActiveSheet
Set rngToSearch = wks.Columns(1)
Set rngFound = rngToSearch.Find(what:="new", _
After:=Range("A1"), _
LookIn:=xlValues, _
SearchOrder:=xlColumns, _
SearchDirection:=xlNext, _
lookat:=xlWhole)

If rngFound Is Nothing Then
MsgBox "Nothing"
Exit Sub
Else
addr = rngFound.Address
Do
r = rngFound.Row
Range("a" & r, "z" & r).Select
With Selection.Interior
.ColorIndex = 36
.Pattern = xlSolid
End With
Range("a" & r).Select
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = addr
End If

End Sub

regards
FSt1
"John" wrote:

Can someone tell me why this won't find the next value in the loop... it
stays on the first one and crashes my excel...

heets("c").Select
Set wks = ActiveSheet
Set rngToSearch = wks.Columns(1)
Set RngFound = rngToSearch.Find(what:="new", LookIn:=xlValues,
lookat:=xlWhole)
If RngFound Is Nothing Then
MsgBox "Nothing"
Else
Do
r = RngFound.Row
Range("a" & r, "z" & r).Select
With Selection.Interior
.ColorIndex = 36
.Pattern = xlSolid
End With
Range("a" & r).Select
Set RngFound = rngToSearch.FindNext
Loop Until RngFound Is Nothing
End If
End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default loop and findnext

Thanks! That works as well.

"FSt1" wrote:

hi,
i copied your code and tried to run it. got caught in an endless loop. so i
re-wrote i a little. your main problem was in the do loop.

Sub macfindit()
Dim wks As Worksheet
Dim rngToSearch As Range
Dim rngFound As Range
Dim r As Long
Dim addr As String

'Sheets("Sheet1").Select
Set wks = ActiveSheet
Set rngToSearch = wks.Columns(1)
Set rngFound = rngToSearch.Find(what:="new", _
After:=Range("A1"), _
LookIn:=xlValues, _
SearchOrder:=xlColumns, _
SearchDirection:=xlNext, _
lookat:=xlWhole)

If rngFound Is Nothing Then
MsgBox "Nothing"
Exit Sub
Else
addr = rngFound.Address
Do
r = rngFound.Row
Range("a" & r, "z" & r).Select
With Selection.Interior
.ColorIndex = 36
.Pattern = xlSolid
End With
Range("a" & r).Select
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = addr
End If

End Sub

regards
FSt1
"John" wrote:

Can someone tell me why this won't find the next value in the loop... it
stays on the first one and crashes my excel...

heets("c").Select
Set wks = ActiveSheet
Set rngToSearch = wks.Columns(1)
Set RngFound = rngToSearch.Find(what:="new", LookIn:=xlValues,
lookat:=xlWhole)
If RngFound Is Nothing Then
MsgBox "Nothing"
Else
Do
r = RngFound.Row
Range("a" & r, "z" & r).Select
With Selection.Interior
.ColorIndex = 36
.Pattern = xlSolid
End With
Range("a" & r).Select
Set RngFound = rngToSearch.FindNext
Loop Until RngFound Is Nothing
End If
End Sub

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
Findnext Noemi Excel Discussion (Misc queries) 1 December 12th 05 11:23 AM
Using 'Find' and 'FindNext' in vba SA3214 Excel Programming 3 March 25th 05 12:17 PM
Find, Findnext VBA Loop SMS - John Howard Excel Programming 5 November 13th 04 03:19 AM
FindNext John Keturi Excel Programming 1 October 16th 04 01:56 PM
FindNext SJ[_6_] Excel Programming 7 May 21st 04 06:01 AM


All times are GMT +1. The time now is 05:55 PM.

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

About Us

"It's about Microsoft Excel"