ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Finding a Range Name (https://www.excelbanter.com/excel-programming/315411-finding-range-name.html)

James Montgomery

Finding a Range Name
 
Hi,

The code below when finding the Range Name and when the name is exists on
the sheet it runs ok but when it does not find the Range Name ("Stop") it
blows up with a run time error that reads 'Global Method Failed'

Can someone help and show me what is wrong or the proper way to code this.


If Not Range(Range("D101"), Range("D65536")) _
.Find(Range("Stop")) Is Nothing Then GoTo NextStep
(MyCode)
Exit Sub
NextStep:
(MyCode)



crispbd[_6_]

Finding a Range Name
 

You just need an error-handling event in the code.
This On Error will trigger the procedure to end

Sub ProcedureName
On Error Goto MyErrorHandler

//
your code here
//
Exit Sub
MyErrorHandler:
End Su

--
crispb
-----------------------------------------------------------------------
crispbd's Profile: http://www.excelforum.com/member.php...fo&userid=1088
View this thread: http://www.excelforum.com/showthread.php?threadid=27419


Tom Ogilvy

Finding a Range Name
 
Dim rng as Range, rng1 as Range
on Error Resume next
set rng = Range("Stop")
on Error goto 0
if not rng is nothing then
set rng1 = Range("D101:D65536") _
.Find(rng.Value)
if not rng1 is nothing then
' now you can run your code and
' use rng1 if you need to
end if
end if
Next Step:

Not sure what action should be taken if Range("Stop") is not found, but the
above portion of code won't blow up.

--
Regards,
Tom Ogilvy

"James Montgomery" wrote in message
...
Hi,

The code below when finding the Range Name and when the name is exists on
the sheet it runs ok but when it does not find the Range Name ("Stop") it
blows up with a run time error that reads 'Global Method Failed'

Can someone help and show me what is wrong or the proper way to code this.


If Not Range(Range("D101"), Range("D65536")) _
.Find(Range("Stop")) Is Nothing Then GoTo NextStep
(MyCode)
Exit Sub
NextStep:
(MyCode)





James Montgomery

Finding a Range Name
 
Thanks for all help
James

"James Montgomery" wrote in message
...
Hi,

The code below when finding the Range Name and when the name is exists on
the sheet it runs ok but when it does not find the Range Name ("Stop") it
blows up with a run time error that reads 'Global Method Failed'

Can someone help and show me what is wrong or the proper way to code this.


If Not Range(Range("D101"), Range("D65536")) _
.Find(Range("Stop")) Is Nothing Then GoTo NextStep
(MyCode)
Exit Sub
NextStep:
(MyCode)






All times are GMT +1. The time now is 09:14 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com