ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   cell format (https://www.excelbanter.com/excel-programming/286778-cell-format.html)

mike

cell format
 
I've set a column of cells to be formatted as mm/dd/yyyy,
however when i move the date value of one of these cells
to a string variable, the value in the variable is
displayed as my regional option for the short date which
is mmddyy. Is there a way around this. Can you set the
regional system options with VBA and then reset when the
spreadsheet application is closed?

Thanks,
Mike

Tom Ogilvy

cell format
 
Dim sStr as String
sStr = Range("A1").Text

Demoing from the immediate window:

range("A1").Value = Date
range("A1").NumberFormat = "mmmm dd, yyyy"
? range("A1").Value
1/3/04
? range("A1").Text
January 03, 2004
sStr = range("A1").Text
? sStr
January 03, 2004


--
Regards,
Tom Ogilvy


Mike wrote in message
...
I've set a column of cells to be formatted as mm/dd/yyyy,
however when i move the date value of one of these cells
to a string variable, the value in the variable is
displayed as my regional option for the short date which
is mmddyy. Is there a way around this. Can you set the
regional system options with VBA and then reset when the
spreadsheet application is closed?

Thanks,
Mike





All times are GMT +1. The time now is 09:16 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com