Finding a Range Name

  • Thread starter Thread starter James Montgomery
  • Start date Start date
J

James Montgomery

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)
 
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
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top