"If c is Nothing" v "If Not c is Nothing"

LEXCERM

Active Member
Joined
Jun 26, 2004
Messages
320
Office Version
  1. 365
Platform
  1. Windows
Hi,

Need an answer to a simple question please. Both statements below work, but why is it that whenever I read topics on this, people always use "If NOT c is Nothing"? Is there an advantage of writing it this way?

Example A:
Code:
Set c = Cells.Find("Dave")
If Not c Is Nothing Then
MsgBox "found"
Else
MsgBox "not Found"
End If

Example B:
Code:
Set c = Cells.Find("Dave")
If c Is Nothing Then
MsgBox "not found"
Else
MsgBox "found"
End If

Thanks!
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
These are functionally equivalent:

Code:
if myString <> "Bob" then
  msgbox "It's not Bob"
else
  msgbox "It's Bob"
endif

if myString = "Bob" then
  msgbox "It's Bob"
else
  msgbox "It's not Bob"
endif

Your example is the analog for objects, but there is no "<> Nothing" syntax for objects.

I tend to prefer B just to avoid the use of the additional operator, but the difference is minute, and would use A if I saw any advantage of clarity.
 
Last edited:
Upvote 0
Thank you for the clarification shg. Just wanted to see if I was missing something glaringly obvious. "If NOT" seems to be the preferred methond for the majority of people, but for simplicity example B seems easier to follow.
 
Upvote 0

Forum statistics

Threads
1,215,044
Messages
6,122,827
Members
449,096
Latest member
Erald

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