Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 422
Default Code bombing on Loop While line

The below code I copied from the Help screen under the Find Method of the Range
Object:
It is properly changing 2 values to 5 values, but before concluding it is
"bombing" on the 3rd from the last line (below);
Can someone spot what the problem is?
TIA,

With Worksheets(1).Range("A1:A10")
Set c = .Find(2, LookIn:=xlValues)
If Not c Is Nothing Then
firstaddress = c.Address
Do
c.Value = 5
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstaddress
End If
End With


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Code bombing on Loop While line

Jim,

Try this

With Worksheets(1).Range("A1:A10")
Set c = .Find(2, LookIn:=xlValues)
If Not c Is Nothing Then
firstaddress = c.Address
Do
c.Value = 5
Set c = .FindNext(c)
Loop While Not c Is Nothing
End If
End With

--

HTH

RP
(remove nothere from the email address if mailing direct)


"JMay" wrote in message
news:xoYrf.105610$WH.103657@dukeread01...
The below code I copied from the Help screen under the Find Method of the

Range
Object:
It is properly changing 2 values to 5 values, but before concluding it is
"bombing" on the 3rd from the last line (below);
Can someone spot what the problem is?
TIA,

With Worksheets(1).Range("A1:A10")
Set c = .Find(2, LookIn:=xlValues)
If Not c Is Nothing Then
firstaddress = c.Address
Do
c.Value = 5
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstaddress
End If
End With




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default Code bombing on Loop While line

JMay,

I notice that the code you used is straight from XL Help (2003 at least) and
is also shown this way on MS 's web site. The reason it didn't work is
because the found values are changed, which means that c will eventually be
nothing when all the 2's are found. This generates the error ,i.e., the
address of nothing. Conversely if you are changing a property of the found
cells, e.g., the color, you need the "c.address < firstaddress". I think
you could eliminate the "not c is nothing" (at least in 2003, not sure about
earlier):

With Worksheets(1).Range("a1:a10")
Set c = .Find(2, LookIn:=xlValues)
If Not c Is Nothing Then
firstaddress = c.Address
Do
c.Interior.ColorIndex = 5
Set c = .FindNext(c)
Loop While c.Address < firstaddress
End If
End With

Maybe more than you wanted to know, but it tool me a while to figure out...

Doug


"JMay" wrote in message
news:xoYrf.105610$WH.103657@dukeread01...
The below code I copied from the Help screen under the Find Method of the
Range Object:
It is properly changing 2 values to 5 values, but before concluding it is
"bombing" on the 3rd from the last line (below);
Can someone spot what the problem is?
TIA,

With Worksheets(1).Range("A1:A10")
Set c = .Find(2, LookIn:=xlValues)
If Not c Is Nothing Then
firstaddress = c.Address
Do
c.Value = 5
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstaddress
End If
End With



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 422
Default Code bombing on Loop While line

Doug Thanks,
Bob, I'm sure recognized in a second (what the problem was)
and submitted revise code;
I'm sure you have seen it bye now,,,
Tks,
Jim


"Doug Glancy" wrote in message
...
JMay,

I notice that the code you used is straight from XL Help (2003 at least) and
is also shown this way on MS 's web site. The reason it didn't work is
because the found values are changed, which means that c will eventually be
nothing when all the 2's are found. This generates the error ,i.e., the
address of nothing. Conversely if you are changing a property of the found
cells, e.g., the color, you need the "c.address < firstaddress". I think you
could eliminate the "not c is nothing" (at least in 2003, not sure about
earlier):

With Worksheets(1).Range("a1:a10")
Set c = .Find(2, LookIn:=xlValues)
If Not c Is Nothing Then
firstaddress = c.Address
Do
c.Interior.ColorIndex = 5
Set c = .FindNext(c)
Loop While c.Address < firstaddress
End If
End With

Maybe more than you wanted to know, but it tool me a while to figure out...

Doug


"JMay" wrote in message
news:xoYrf.105610$WH.103657@dukeread01...
The below code I copied from the Help screen under the Find Method of the
Range Object:
It is properly changing 2 values to 5 values, but before concluding it is
"bombing" on the 3rd from the last line (below);
Can someone spot what the problem is?
TIA,

With Worksheets(1).Range("A1:A10")
Set c = .Find(2, LookIn:=xlValues)
If Not c Is Nothing Then
firstaddress = c.Address
Do
c.Value = 5
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstaddress
End If
End With





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
Macro code to put series name next to individual line in line grap Otani Charts and Charting in Excel 3 February 23rd 10 07:24 PM
Loop Code sheeba Excel Programming 0 December 4th 05 06:12 AM
Macro bombing out CyberFox Excel Programming 13 November 10th 05 09:58 AM
Macro Bombing out - Leith Ross CyberFox[_2_] Excel Programming 0 November 9th 05 08:42 AM
Help with loop code... gaba Excel Programming 1 October 20th 04 01:37 PM


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