missed ranges and the find function...

Engineer Joe

Well-known Member
Joined
Jun 10, 2005
Messages
549
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

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
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
'-----------------------------------------
 
Upvote 0

Forum statistics

Threads
1,214,965
Messages
6,122,499
Members
449,089
Latest member
Raviguru

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
Back
Top