Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default problem with dates

Hi,
how can i verify if a value is a date or a numeric befor copy it to a
target cell in order to change the target cell number format
accordingly.

for an example:
I need to copy a value from cell a1 to cell a2.

I do not know what will be the value in cell a1 (it can be a date or a
number)and i want to adjust the a2 cell's number format according to
the type data in cell a1 in order to view the value in cell a2 in its
correct format.

when i copy the value from a1 to a2, if the value in a1 is a number
(i.e. 1234) the value that excel will show in cell a2 will also be
1234. but if there is a date value in cell a1 (i.e 01/01/2002), excel
will show in cell a2 the long value of the date (i.e. in cell a2 we
will see the value 37257 and not as it should be - 01/01/2002).
looking for your kind reply. thanks
Alex g
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default problem with dates

Alex,

You should investigate IsDate and IsNumeric VBA functions.

Sub testit()
With Range("A1")
If IsDate(.Value) Then
MsgBox "Date"
ElseIf IsNumeric(.Value) Then
MsgBox "Numeric"
Else
MsgBox "Not date or numeric"
End If
End With
End Sub

Rob

"Alex G" wrote in message
om...
Hi,
how can i verify if a value is a date or a numeric befor copy it to a
target cell in order to change the target cell number format
accordingly.

for an example:
I need to copy a value from cell a1 to cell a2.

I do not know what will be the value in cell a1 (it can be a date or a
number)and i want to adjust the a2 cell's number format according to
the type data in cell a1 in order to view the value in cell a2 in its
correct format.

when i copy the value from a1 to a2, if the value in a1 is a number
(i.e. 1234) the value that excel will show in cell a2 will also be
1234. but if there is a date value in cell a1 (i.e 01/01/2002), excel
will show in cell a2 the long value of the date (i.e. in cell a2 we
will see the value 37257 and not as it should be - 01/01/2002).
looking for your kind reply. thanks
Alex g



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default problem with dates

Range("A2").Value = Range("A1").Value
Range("A2").NumberFormat = Range("A1").Numberformat

--
Regards,
Tom Ogilvy


Alex G wrote in message
om...
Hi,
how can i verify if a value is a date or a numeric befor copy it to a
target cell in order to change the target cell number format
accordingly.

for an example:
I need to copy a value from cell a1 to cell a2.

I do not know what will be the value in cell a1 (it can be a date or a
number)and i want to adjust the a2 cell's number format according to
the type data in cell a1 in order to view the value in cell a2 in its
correct format.

when i copy the value from a1 to a2, if the value in a1 is a number
(i.e. 1234) the value that excel will show in cell a2 will also be
1234. but if there is a date value in cell a1 (i.e 01/01/2002), excel
will show in cell a2 the long value of the date (i.e. in cell a2 we
will see the value 37257 and not as it should be - 01/01/2002).
looking for your kind reply. thanks
Alex g



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
Dates problem Andrew Mackenzie Excel Discussion (Misc queries) 2 December 29th 08 04:06 PM
Problem with dates Carpe Diem Excel Worksheet Functions 2 September 11th 07 12:21 PM
dates problem mita Excel Discussion (Misc queries) 4 June 2nd 06 12:19 PM
Dates Problem nicole0904 Excel Discussion (Misc queries) 5 May 10th 06 02:47 PM
Problem Dates Andy Cohen Excel Discussion (Misc queries) 1 September 16th 05 01:29 AM


All times are GMT +1. The time now is 03:33 PM.

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

About Us

"It's about Microsoft Excel"