Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dealing with 'empty' cells in a formula

Status
Not open for further replies.

t16turbo

Programmer
Mar 22, 2005
315
GB
My spreadsheet has some empty cells in it.

I have tried using the code
Code:
If IsNull(ActiveCell.Value) Then
my_variable = 0
Else: my_variable = ActiveCell.Value
End If

but this doesn't work, as it just goes straight into the Else section.
How can I cater for empty cells?

 
maybe

If ActiveCell.Value & "" = "" Then
my_variable = 0
Else
my_variable = ActiveCell.Value
End If
 
Or perhaps this:
If Trim(ActiveCell.Value & "") = "" Then

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 


Hi,

FYI...

EMPTY means the the cell contains neither a VALUE nor a FORMULA. Even if a formula returns "", it is NOT EMPTY.


Skip,

[glasses] [red]Be Advised![/red]
A wee deranged psychic may be runnin' around out there!
SMALL MEDUIM @ LARGE[tongue]
 
If the cell contains nothing not even "" ....try

If IsEmpty(ActiveCell)=True then
my_variable=0
Else
my_variable=ActiveCell.Value
End If

Null is not the same as Empty, which indicates that a variable has not yet been initialized. It is also not the same as a zero-length string (""), which is sometimes referred to as a null string.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top