Logical tests

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

Hello,

There may be more but when applying logical tests to a cell to check if it
is empty there are 3 common ones that seem to be used...

Range("A1").text
Range("A1").value
Isempty(Range("A1")

When would each be used?

D
 
The first two returns the text or value, where text is the string and value
is a variant. How you then use this value depends on what you intend to do
with it. The last is a logical test for a variable as to whether it has
been initialized. Therefore all three at not the same.

To be strictly applied then IsEmpty should read

IsEmpty(Range("A1").Value); is effectively doing the first by returning the
value from the cell A1 then applying a logical test to determine if it has
been initialized; if the cell has a value (not Null) then it returns true.
So If Range("A1").Value = "" then and IsEmpty(Range("A1").Value) are
equivalent in this case.

Note: That using IsEmpty only returns meaningful results for variants,
Range("A1").Text does not return a variant but text.
 
Note that .Value returns the underlying value in a cell, .Text returns what
you see. For instance, if a cell has a date, .Value returns the number of
days since 1st Jan 1900, which is how Excel stores dates, whereas .Text will
return the date as formatted, such as 01/02/2008.

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)
 

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