#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default null date?

1. On the worksheet a cell is formated as date.
In vb is a variable also formated as date
If I have variable = cell I get a formating error if the cell is empty
I can use isempty or isdate first to test the cell but seems like a pain

2. cell is formated as date like 01/01/09
If someone enters the date in the cell as 1/01/09 then get an error if
try to set the cell = variable formated as date.

In general I'm having trouble working with dates I guess. In the program
data is entered directly into the worksheet by the operator.

Thanks

John
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 449
Default null date?

Hi John

A date is simply X days since new year to 1900. Try this:
Enter 40000 into a cell.
Format it as any date format. The formula bar will also show a date, in the
same or a different date format. Format the cell as another date format, the
formula bar shows the same as before.
Meaning a date is a date, formatting is for cell display only.

What may cause trouble is that cells can contain text that looks like dates,
but are just text. Then the formula bar does not display its normal date
format, and the text gets left aligned in stead of default rigth.

Try running this when in an empty cell, no error:

Sub test()
Dim D As Date
D = ActiveCell.Value
MsgBox Format(D, "yyyy.mm.dd")
End Sub

HTH. Best wishes Harald


"John" wrote in message
...
1. On the worksheet a cell is formated as date.
In vb is a variable also formated as date
If I have variable = cell I get a formating error if the cell is empty
I can use isempty or isdate first to test the cell but seems like a pain

2. cell is formated as date like 01/01/09
If someone enters the date in the cell as 1/01/09 then get an error if try
to set the cell = variable formated as date.

In general I'm having trouble working with dates I guess. In the program
data is entered directly into the worksheet by the operator.

Thanks

John


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default null date?

John,

try to set the cell = variable formated as date


Try using this if your variable is a string

Dim variable As String
variable = "1/1/9"
ActiveCell.Value = DateValue(variable)


or, if it is a date

Dim variable As Date
variable = DateValue("1/1/9")
ActiveCell.Value = variable


HTH,
Bernie

"John" wrote in message
...
1. On the worksheet a cell is formated as date.
In vb is a variable also formated as date
If I have variable = cell I get a formating error if the cell is empty
I can use isempty or isdate first to test the cell but seems like a pain

2. cell is formated as date like 01/01/09
If someone enters the date in the cell as 1/01/09 then get an error if try
to set the cell = variable formated as date.

In general I'm having trouble working with dates I guess. In the program
data is entered directly into the worksheet by the operator.

Thanks

John



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
Null date in VBA variable Den Excel Programming 5 May 14th 23 03:44 AM
Returning date instead of 'not null' Skeeterj Excel Worksheet Functions 4 November 3rd 09 04:40 PM
Date Formula Problem - Leave date blank if Null Gayla Excel Worksheet Functions 5 April 24th 07 09:42 PM
If Date Null Show Nothing Ardy Excel Worksheet Functions 7 January 25th 07 06:12 PM
Date Not Null Rick_C Excel Programming 5 February 2nd 06 11:20 PM


All times are GMT +1. The time now is 08:34 PM.

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

About Us

"It's about Microsoft Excel"