Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Date not Saving As Expected

I have this code in a VBA module:

Rows(1).Insert
Range("A1").Value = "H"
Range("B1").Value = SheetName
Range("C1").Value = Date
Range("C1").NumberFormat = "m/dd/yyyy"
Range("C1").NumberFormat = "@"

When debugging, it returns the correct date,
yet when I view the modified worksheet, this
date is displayed as a number, then stored as
one. How can I ensure that it is saved in m/dd/yyyy
format? I've tried this with and without that last NumberFormat
statement with the same result.

Kevin

--
Message posted via http://www.officekb.com
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default Date not Saving As Expected

hi Kdub
you have a wrong line
try this

"Kdub via OfficeKB.com" wrote:
Rows(1).Insert
Range("A1").Value = "H"
Range("B1").Value = SheetName
Range("C1").Value = Date
Range("C1").NumberFormat = "m/dd/yyyy"

I have this code in a VBA module:

Rows(1).Insert
Range("A1").Value = "H"
Range("B1").Value = SheetName
Range("C1").Value = Date
Range("C1").NumberFormat = "m/dd/yyyy"
Range("C1").NumberFormat = "@"

When debugging, it returns the correct date,
yet when I view the modified worksheet, this
date is displayed as a number, then stored as
one. How can I ensure that it is saved in m/dd/yyyy
format? I've tried this with and without that last NumberFormat
statement with the same result.

Kevin

--
Message posted via http://www.officekb.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Date not Saving As Expected

Thanks for you help, but that gave me the same result. Here
is what I found that works:

Rows(1).Insert
Range("A1").Value = "H"
Range("B1").Value = SheetName
Range("C1").NumberFormat = "@"
Range("C1") = Format(Date, ("MM/DD/YYYY"))

If I format the cell as text before storing the formatted date,
it stores my date in the correct format.
Thanks for the help.

Kevin

--
Message posted via http://www.officekb.com
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Date not Saving As Expected

It may store it to appear as the correct format, but it isn't being stored
as a date value - at least not running your code in xl2003, US English.

--
Regards,
Tom Ogilvy

"Kdub via OfficeKB.com" wrote in message
...
Thanks for you help, but that gave me the same result. Here
is what I found that works:

Rows(1).Insert
Range("A1").Value = "H"
Range("B1").Value = SheetName
Range("C1").NumberFormat = "@"
Range("C1") = Format(Date, ("MM/DD/YYYY"))

If I format the cell as text before storing the formatted date,
it stores my date in the correct format.
Thanks for the help.

Kevin

--
Message posted via http://www.officekb.com



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
saving a file with a date pat67 Excel Worksheet Functions 3 October 8th 09 08:39 PM
Saving with name and date macro Bobby Excel Discussion (Misc queries) 4 December 25th 08 03:37 PM
save as future date eg expected delivery date ryan Excel Discussion (Misc queries) 0 June 21st 07 03:35 PM
Modify Date Changes when NOT saving LoriStar Excel Discussion (Misc queries) 1 December 10th 04 12:14 AM
Saving with date in filename Ben Allen Excel Programming 3 April 26th 04 09:05 AM


All times are GMT +1. The time now is 01:35 AM.

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"