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

in the help, they use firstaddress = c.address so the code doesn't loop
continuously

if i use similar, it generates an error, but my code seems to run fine, what's
the difference?

With ws.Range("C1:C" & lastRow)
Set rngFound = .Find(What:="<", LookIn:=xlValues)
Do
If Not rngFound Is Nothing Then
rngFound.Value = Replace(Replace(rngFound.Value, "<", "-", 1), "",
_
"")
rngFound.NumberFormat = "#,##0_);[Red](#,##0.00)"
Set rngFound = .FindNext(rngFound)
End If
Loop While Not rngFound Is Nothing
End With


--


Gary



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

Hi Gary,

In your example you replace the search string in each found cell, so
eventually the search string will not be found and rngFound = (ie Is)
nothing. If you comment your replace line your code would run continuously
looping back to the first found(assuming a found) unless you amend to
something similar to the help example.

Regards,
Peter T

"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
in the help, they use firstaddress = c.address so the code doesn't loop
continuously

if i use similar, it generates an error, but my code seems to run fine,

what's
the difference?

With ws.Range("C1:C" & lastRow)
Set rngFound = .Find(What:="<", LookIn:=xlValues)
Do
If Not rngFound Is Nothing Then
rngFound.Value = Replace(Replace(rngFound.Value, "<", "-", 1),

"",
_
"")
rngFound.NumberFormat = "#,##0_);[Red](#,##0.00)"
Set rngFound = .FindNext(rngFound)
End If
Loop While Not rngFound Is Nothing
End With


--


Gary





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default findnext question

This line from VBAs help:

Loop While Not c Is Nothing And c.Address < firstAddress

will blow up if c is nothing (since c.address will return an error).

If you weren't removing the seached value, then the .findnext() would loop until
it got to the first found cell and never be nothing.

Gary Keramidas wrote:

in the help, they use firstaddress = c.address so the code doesn't loop
continuously

if i use similar, it generates an error, but my code seems to run fine, what's
the difference?

With ws.Range("C1:C" & lastRow)
Set rngFound = .Find(What:="<", LookIn:=xlValues)
Do
If Not rngFound Is Nothing Then
rngFound.Value = Replace(Replace(rngFound.Value, "<", "-", 1), "",
_
"")
rngFound.NumberFormat = "#,##0_);[Red](#,##0.00)"
Set rngFound = .FindNext(rngFound)
End If
Loop While Not rngFound Is Nothing
End With

--

Gary


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default findnext question

ok, thanks to both for the explanation. so, in the help example for findnext, is
"Loop While Not c Is Nothing And c.Address < firstAddress"
needed? it's changing 2 to 5, so i would think that line isn't needed, either.

--


Gary


"Dave Peterson" wrote in message
...
This line from VBAs help:

Loop While Not c Is Nothing And c.Address < firstAddress

will blow up if c is nothing (since c.address will return an error).

If you weren't removing the seached value, then the .findnext() would loop
until
it got to the first found cell and never be nothing.

Gary Keramidas wrote:

in the help, they use firstaddress = c.address so the code doesn't loop
continuously

if i use similar, it generates an error, but my code seems to run fine,
what's
the difference?

With ws.Range("C1:C" & lastRow)
Set rngFound = .Find(What:="<", LookIn:=xlValues)
Do
If Not rngFound Is Nothing Then
rngFound.Value = Replace(Replace(rngFound.Value, "<", "-", 1),
"",
_
"")
rngFound.NumberFormat = "#,##0_);[Red](#,##0.00)"
Set rngFound = .FindNext(rngFound)
End If
Loop While Not rngFound Is Nothing
End With

--

Gary


--

Dave Peterson



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default findnext question

Worse than not needed. It causes a run time error for me.

But that example was changed from an earlier version. In an earlier version, it
changed colors--not values. When they changed the example, they broke it.

Gary Keramidas wrote:

ok, thanks to both for the explanation. so, in the help example for findnext, is
"Loop While Not c Is Nothing And c.Address < firstAddress"
needed? it's changing 2 to 5, so i would think that line isn't needed, either.

--

Gary

"Dave Peterson" wrote in message
...
This line from VBAs help:

Loop While Not c Is Nothing And c.Address < firstAddress

will blow up if c is nothing (since c.address will return an error).

If you weren't removing the seached value, then the .findnext() would loop
until
it got to the first found cell and never be nothing.

Gary Keramidas wrote:

in the help, they use firstaddress = c.address so the code doesn't loop
continuously

if i use similar, it generates an error, but my code seems to run fine,
what's
the difference?

With ws.Range("C1:C" & lastRow)
Set rngFound = .Find(What:="<", LookIn:=xlValues)
Do
If Not rngFound Is Nothing Then
rngFound.Value = Replace(Replace(rngFound.Value, "<", "-", 1),
"",
_
"")
rngFound.NumberFormat = "#,##0_);[Red](#,##0.00)"
Set rngFound = .FindNext(rngFound)
End If
Loop While Not rngFound Is Nothing
End With

--

Gary


--

Dave Peterson


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default findnext question

But that example was changed from an earlier version.

Here's the Find example as quoted similarly in both XL97 and XL2000 -

Find Method Example

This example finds all cells in the range A1:A500 on worksheet one that
contain the value 2, and then it makes those cells gray.

With Worksheets(1).Range("a1:a500")
Set c = .Find(2, lookin:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.Interior.Pattern = xlPatternGray50
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress
End If
End With

Regards,
Peter T


"Dave Peterson" wrote in message
...
Worse than not needed. It causes a run time error for me.

But that example was changed from an earlier version. In an earlier

version, it
changed colors--not values. When they changed the example, they broke it.

Gary Keramidas wrote:

ok, thanks to both for the explanation. so, in the help example for

findnext, is
"Loop While Not c Is Nothing And c.Address < firstAddress"
needed? it's changing 2 to 5, so i would think that line isn't needed,

either.

--

Gary

"Dave Peterson" wrote in message
...
This line from VBAs help:

Loop While Not c Is Nothing And c.Address < firstAddress

will blow up if c is nothing (since c.address will return an error).

If you weren't removing the seached value, then the .findnext() would

loop
until
it got to the first found cell and never be nothing.

Gary Keramidas wrote:

in the help, they use firstaddress = c.address so the code doesn't

loop
continuously

if i use similar, it generates an error, but my code seems to run

fine,
what's
the difference?

With ws.Range("C1:C" & lastRow)
Set rngFound = .Find(What:="<", LookIn:=xlValues)
Do
If Not rngFound Is Nothing Then
rngFound.Value = Replace(Replace(rngFound.Value, "<",

"-", 1),
"",
_
"")
rngFound.NumberFormat = "#,##0_);[Red](#,##0.00)"
Set rngFound = .FindNext(rngFound)
End If
Loop While Not rngFound Is Nothing
End With

--

Gary

--

Dave Peterson


--

Dave Peterson



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 problem [email protected] Excel Programming 3 July 21st 06 09:23 PM
Findnext Noemi Excel Discussion (Misc queries) 1 December 12th 05 11:23 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 01:13 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"