Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Date Format Problem

I have the following bit of code below that for some reason when run a
message box displays 01/02/2005 as it should but when the value is placed in
a cell it changes to 02/01/2005. I have tried this with month 03, 04 etc and
still the same. I have tried formatting the cell before hand and even
afterwards it thinks its 2nd Jan 2005 rather than 1st Feb 2005 (British
region).
Any ideas anyone???

Thanks
MC
---------------------------
Sub WRITEDATE()
Dim dateandtime As String

dateandtime = "01/02/2005 08:35"
date1 = Left(dateandtime, 10)
MsgBox date1 'to test
Cells(1, 1) = date1 'have tried cells(1,1).value=date1 but same results

End Sub
---------------------
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Date Format Problem

use cDate

change
Cells(1, 1) = date1
to

Cells(1, 1) = cDate(date1)

cDate will observe your regional settings.

--
Regards,
Tom Ogilvy


"Mario" wrote in message
...
I have the following bit of code below that for some reason when run a
message box displays 01/02/2005 as it should but when the value is placed

in
a cell it changes to 02/01/2005. I have tried this with month 03, 04 etc

and
still the same. I have tried formatting the cell before hand and even
afterwards it thinks its 2nd Jan 2005 rather than 1st Feb 2005 (British
region).
Any ideas anyone???

Thanks
MC
---------------------------
Sub WRITEDATE()
Dim dateandtime As String

dateandtime = "01/02/2005 08:35"
date1 = Left(dateandtime, 10)
MsgBox date1 'to test
Cells(1, 1) = date1 'have tried cells(1,1).value=date1 but same results

End Sub
---------------------



  #3   Report Post  
Posted to microsoft.public.excel.programming
Ben Ben is offline
external usenet poster
 
Posts: 509
Default Date Format Problem

that code you have written works perfect for me, 1/02/2005 in msgbox and in
cell
try to Dim dateandtime as date instead of string and have the time as a
seperate string and just put them together when needed


"Mario" wrote:

I have the following bit of code below that for some reason when run a
message box displays 01/02/2005 as it should but when the value is placed in
a cell it changes to 02/01/2005. I have tried this with month 03, 04 etc and
still the same. I have tried formatting the cell before hand and even
afterwards it thinks its 2nd Jan 2005 rather than 1st Feb 2005 (British
region).
Any ideas anyone???

Thanks
MC
---------------------------
Sub WRITEDATE()
Dim dateandtime As String

dateandtime = "01/02/2005 08:35"
date1 = Left(dateandtime, 10)
MsgBox date1 'to test
Cells(1, 1) = date1 'have tried cells(1,1).value=date1 but same results

End Sub
---------------------

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 95
Default Date Format Problem

Hi Markus,

I assume your problem is caused by the automatically
changing of a cell format within excel.

message box displays 01/02/2005 as it should but when the

value is placed in
a cell it changes to 02/01/2005. I have tried this with


Sub WRITEDATE()
Dim dateandtime As String

dateandtime = "01/02/2005 08:35"
date1 = Left(dateandtime, 10)
MsgBox date1 'to test
Cells(1, 1) = date1 'have tried cells(1,1).value=date1

but same results

Try range("A1").Value = date1

and go to Format = Cells = Number = Custom = TT/MM/JJJJ


Best

Markus


End Sub
---------------------
.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Date Format Problem

The cell contained the date Feb 1, 2005?

--
Regards,
Tom Ogilvy

"ben" wrote in message
...
that code you have written works perfect for me, 1/02/2005 in msgbox and

in
cell
try to Dim dateandtime as date instead of string and have the time as a
seperate string and just put them together when needed


"Mario" wrote:

I have the following bit of code below that for some reason when run a
message box displays 01/02/2005 as it should but when the value is

placed in
a cell it changes to 02/01/2005. I have tried this with month 03, 04 etc

and
still the same. I have tried formatting the cell before hand and even
afterwards it thinks its 2nd Jan 2005 rather than 1st Feb 2005 (British
region).
Any ideas anyone???

Thanks
MC
---------------------------
Sub WRITEDATE()
Dim dateandtime As String

dateandtime = "01/02/2005 08:35"
date1 = Left(dateandtime, 10)
MsgBox date1 'to test
Cells(1, 1) = date1 'have tried cells(1,1).value=date1 but same results

End Sub
---------------------





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Date Format Problem

CDATE worked fine.

Thanks

MC

"Tom Ogilvy" wrote:

use cDate

change
Cells(1, 1) = date1
to

Cells(1, 1) = cDate(date1)

cDate will observe your regional settings.

--
Regards,
Tom Ogilvy


"Mario" wrote in message
...
I have the following bit of code below that for some reason when run a
message box displays 01/02/2005 as it should but when the value is placed

in
a cell it changes to 02/01/2005. I have tried this with month 03, 04 etc

and
still the same. I have tried formatting the cell before hand and even
afterwards it thinks its 2nd Jan 2005 rather than 1st Feb 2005 (British
region).
Any ideas anyone???

Thanks
MC
---------------------------
Sub WRITEDATE()
Dim dateandtime As String

dateandtime = "01/02/2005 08:35"
date1 = Left(dateandtime, 10)
MsgBox date1 'to test
Cells(1, 1) = date1 'have tried cells(1,1).value=date1 but same results

End Sub
---------------------




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
Date Format Problem Alain Excel Discussion (Misc queries) 2 May 31st 10 04:53 PM
Excel Format Problem - Date Overrides Format Mary Excel Discussion (Misc queries) 5 February 10th 10 05:49 AM
Problem with Date format Lise Excel Discussion (Misc queries) 2 August 18th 09 12:21 AM
date format problem?? Steve[_9_] Excel Discussion (Misc queries) 10 December 27th 07 11:23 PM
Date format problem Vass Excel Worksheet Functions 7 April 3rd 06 04:50 PM


All times are GMT +1. The time now is 10:53 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"