missed ranges and the find function...

Engineer Joe

Well-known Member
Joined
Jun 10, 2005
Messages
543
hey you old crusty VBA veterans...here's an easy one for you...

I execute a find procedure on a worksheet, and try to name the range (lets call it "Body") that it finds...like so:

Code:
Set Body = .find(blah,blah,blah)

My question is: what happens when nothing is found? Body has already been defined as a range. But an error is not generated...Not until i try to use Body. I guess what i'm getting at is that i'd like to insert some code that either notifies me, or skips over any arguments that try to use that range after it misses. But I don't know how? Any tips? I love you. I mean, I would be appreciative...
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

BrianB

Well-known Member
Joined
Feb 17, 2003
Messages
8,127
See - you youngsters can't do without us. :p
Try this :-
Code:
Sub test()
    Dim FoundCell As Object
    Dim body As Range
    Set FoundCell = ActiveSheet.Cells.Find(what:="test")
    If FoundCell Is Nothing Then
        MsgBox ("Not found")
    Else
        Set body = FoundCell
        MsgBox (body.Address)
    End If
End Sub
------------------------------------------
I'm off for my afternoon nap now
'-----------------------------------------
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,168,119
Messages
5,857,487
Members
431,882
Latest member
saaaaaaaaaaaaaaaaaaaaaa

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top