If Not... Then Nothing

GreenyMcDuff

Active Member
Joined
Sep 20, 2010
Messages
313
Hi guys,

Just looking for some information here out of curiosity and to expand my knowledge.

I use the If Not... Then Nothing statement a lot to set the true/false of a variable e.g:

Code:
X = False
    Set Xtinct = Range("1:1").Find("Status")
    If Not Xtinct.EntireColumn.Find("Extinct") Is Nothing Then X = True

Why is this code used this way round? is it not possible to say if variable exists then set the variable to true?
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
If the text is not found, Find returns Nothing. If the text is found, Find returns a range object, which is not Nothing. You aren't testing for the existence of a variable. You are testing what's returned by Find.
 
Upvote 0
Thanks Andrew.

So if I wanted to I could write this statement as:

Code:
X = True
    Set Xtinct = Range("1:1").Find("Status")
    If Not Xtinct.EntireColumn.Find("Extinct") Is Not Nothing Then X = False

and it would do the same thing?
 
Upvote 0
Too many Nots:
Code:
If Not Xtinct.EntireColumn.Find("Extinct") Is Nothing Then X = True
or:
Code:
X = Not Xtinct.EntireColumn.Find("Extinct") Is Nothing
 
Upvote 0
Ok thanks Rory,

A slightly different question now.

How does the count command work in excel?

I have this code:

Code:
LastRow = .Cells(Rows.Count, "A").End(xlUp).Row

It counts accurately the number of rows of data in a worksheet even if there are more rows in column B than A. How does it work?
 
Upvote 0
It counts accurately the number of rows of data in a worksheet even if there are more rows in column B than A. How does it work?

There must be something in the corresponding rows for A if it is returning the correct number in those circumstances.
 
Upvote 0

Forum statistics

Threads
1,224,517
Messages
6,179,242
Members
452,898
Latest member
Capolavoro009

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