Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default vba - check if cell is empty


hi,

how can i check if a cell is empty in vba? i am using an if, and woul
like to test if the cell is empty or not.

thank

-----------------------------------------------
~~ Message posted from http://www.ExcelTip.com
~~View and post usenet messages directly from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default vba - check if cell is empty

if IsEmpty(ActiveCell) then msgbox "Cell is empty"



"joao" wrote in message ...

hi,

how can i check if a cell is empty in vba? i am using an if, and would
like to test if the cell is empty or not.

thanks


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default vba - check if cell is empty

Use IsEmpty

Sub test()
If IsEmpty(Range("a1")) Then
MsgBox "empty"
Else
MsgBox "not empty"
End If
End Sub



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"joao" wrote in message ...

hi,

how can i check if a cell is empty in vba? i am using an if, and would
like to test if the cell is empty or not.

thanks


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default vba - check if cell is empty

Ron,

PMFJI, but this seems a good place to ask about empty cells.

VBA Help for IsEmpty says that it checks for uninitialised variables, so
I've been using Range("A1").value = "" to check for an empty cell. Am I
likely to run into trouble doing it this way? Is IsEmpty preferable?

Thanks for any insight.

--
Dianne



In ,
Ron de Bruin typed:
Use IsEmpty

Sub test()
If IsEmpty(Range("a1")) Then
MsgBox "empty"
Else
MsgBox "not empty"
End If
End Sub




"joao" wrote in message
...

hi,

how can i check if a cell is empty in vba? i am using an if, and
would like to test if the cell is empty or not.

thanks


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from
http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default vba - check if cell is empty

Depends on what you're looking for.

if you check
range("a1").value = ""

Then A1 could have a formula that evaluates to "" and this check would return
true.
=if(b132,b1,"")

If you really mean you want the cell to be empty--no value, no formula, then
isempty() is the way to go.



Dianne wrote:

Ron,

PMFJI, but this seems a good place to ask about empty cells.

VBA Help for IsEmpty says that it checks for uninitialised variables, so
I've been using Range("A1").value = "" to check for an empty cell. Am I
likely to run into trouble doing it this way? Is IsEmpty preferable?

Thanks for any insight.

--
Dianne

In ,
Ron de Bruin typed:
Use IsEmpty

Sub test()
If IsEmpty(Range("a1")) Then
MsgBox "empty"
Else
MsgBox "not empty"
End If
End Sub




"joao" wrote in message
...

hi,

how can i check if a cell is empty in vba? i am using an if, and
would like to test if the cell is empty or not.

thanks


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from
http://www.ExcelForum.com/


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 459
Default vba - check if cell is empty

Going even further

range("a1").Text = ""

may also give different results.

Note that it is clearer to use

range("a1").Text = vbNullString

and more effecient to use

Len(range("a1").Text) = 0

over the (very) long run.

Dave Peterson wrote in message ...
Depends on what you're looking for.

if you check
range("a1").value = ""

Then A1 could have a formula that evaluates to "" and this check would return
true.
=if(b132,b1,"")

If you really mean you want the cell to be empty--no value, no formula, then
isempty() is the way to go.



Dianne wrote:

Ron,

PMFJI, but this seems a good place to ask about empty cells.

VBA Help for IsEmpty says that it checks for uninitialised variables, so
I've been using Range("A1").value = "" to check for an empty cell. Am I
likely to run into trouble doing it this way? Is IsEmpty preferable?

Thanks for any insight.

--
Dianne

In ,
Ron de Bruin typed:
Use IsEmpty

Sub test()
If IsEmpty(Range("a1")) Then
MsgBox "empty"
Else
MsgBox "not empty"
End If
End Sub




"joao" wrote in message
...

hi,

how can i check if a cell is empty in vba? i am using an if, and
would like to test if the cell is empty or not.

thanks


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from
http://www.ExcelForum.com/

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default vba - check if cell is empty

Excellent point -- I sometimes use formulas that evaluate to "", and I
hadn't considered this (although so far I haven't checked for empty
cells in these cases).

I shall be switching approach then. Thanks.

--
Dianne

In ,
Dave Peterson typed:
Depends on what you're looking for.

if you check
range("a1").value = ""

Then A1 could have a formula that evaluates to "" and this check
would return true.
=if(b132,b1,"")

If you really mean you want the cell to be empty--no value, no
formula, then isempty() is the way to go.


Dianne wrote:

Ron,

PMFJI, but this seems a good place to ask about empty cells.

VBA Help for IsEmpty says that it checks for uninitialised
variables, so I've been using Range("A1").value = "" to check for an
empty cell. Am I likely to run into trouble doing it this way? Is
IsEmpty preferable?

Thanks for any insight.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check if Conditional Format is True or False / Check cell Color Kevin McCartney Excel Worksheet Functions 5 June 29th 07 11:12 AM
How do I check for an empty cell in a formula? sasquatchbill Excel Discussion (Misc queries) 4 August 8th 06 03:55 PM
Check for empty range in vba Phil Excel Discussion (Misc queries) 1 April 28th 06 09:57 PM
why a reference to an empty cell is not considered empty Nicoscot Excel Discussion (Misc queries) 10 March 10th 06 05:36 AM
If Then's for 12 textboxes to check if they are empty. Beertje Excel Discussion (Misc queries) 3 October 27th 05 02:34 PM


All times are GMT +1. The time now is 03:30 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"