PC Review


Reply
Thread Tools Rate Thread

Date variables and empty cells?

 
 
salgud
Guest
Posts: n/a
 
      29th Jul 2008
I'm working on a program that works with a lot of dates. I found that if I
set a date variable equal to a cell that might contain a date or might be
empty, if the cell is empty, it returns "12:00:00 AM" which I assume to be
midnight, Jan. 1, 1900, which is more difficult to test for than a blank
cell. So it seems to me that it would be better to use a variant type
variable here instead of a date variable since I have to test for blank
cells. The variant returns "empty" for blank cells, and dates for cells
with dates in them. Am I on the right track, or headed off on a spur?

If I do use the variants, how do I test for "Empty"? Is it just "If rRange
= "empty", or do I need to use something else? Will testing for "" work for
this? Basically, I have several tests where if the cell is blank, do
something, if it has a date in it, do something else.

Any thoughts any of you experts has on working with dates and blank cells
will be greatly appreciated.
 
Reply With Quote
 
 
 
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      29th Jul 2008
The problem is not the empty cell, that is returning the empty string; the
problem is you are putting it into a variable declared as being of type
Date. However, this is not hard to test for at all...

If YourDateVariable = 0 Then 'Assume there is no date in the cell

or, you could test the cell directly...

If Range("A1").Value = "" Then 'There is nothing in the cell

Rick


"salgud" <(E-Mail Removed)> wrote in message
news:138gj4se9wpai$.1p50ez9e51wi5$.(E-Mail Removed)...
> I'm working on a program that works with a lot of dates. I found that if I
> set a date variable equal to a cell that might contain a date or might be
> empty, if the cell is empty, it returns "12:00:00 AM" which I assume to be
> midnight, Jan. 1, 1900, which is more difficult to test for than a blank
> cell. So it seems to me that it would be better to use a variant type
> variable here instead of a date variable since I have to test for blank
> cells. The variant returns "empty" for blank cells, and dates for cells
> with dates in them. Am I on the right track, or headed off on a spur?
>
> If I do use the variants, how do I test for "Empty"? Is it just "If rRange
> = "empty", or do I need to use something else? Will testing for "" work
> for
> this? Basically, I have several tests where if the cell is blank, do
> something, if it has a date in it, do something else.
>
> Any thoughts any of you experts has on working with dates and blank cells
> will be greatly appreciated.


 
Reply With Quote
 
ward376
Guest
Posts: n/a
 
      29th Jul 2008
test for 0

Cliff Edwards

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Empty cells showing that they are default formated to "Date" FredC Microsoft Excel Misc 1 1st Dec 2009 10:36 PM
Count cell with date-entrie, not include empty cells Twisty Microsoft Access Reports 5 17th Jul 2009 11:51 AM
Excel: Format empty date cells kogrady Microsoft Excel Misc 3 8th Jul 2009 10:04 PM
macro to colour empty cells (cells not recognized as empty) Gerben Microsoft Excel Programming 5 30th Jun 2005 03:29 PM
Can blank cells created using empty Double-Quotes not be empty?? JohnI in Brisbane Microsoft Excel Programming 6 7th Sep 2003 11:22 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:48 AM.