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

Can anyone tell me how to format a cell so that when a
date is entered it formats as a date and when a number is
entered it formats as a number.

If you use general it auto formats for a date but if you
enter a number in the same cell after a date has been
entered then it still thinks it's a date.

Any help will be appreciated.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Format date and number

Cindy,

You're out of luck. To Excel, dates are numbers, and numbers are numbers.
If you don't apply any formatting, Excel will format any strings entered as
valid dates as dates, then convert them to the proper number. Numbers it
will leave as"general".

So, enter your date as a valid date string, like 5/14/2004, and Excel will
know it is a date. However, once a cell ahs been autoformatted as a date, it
will stay a date. If you want to do what you describe, you do need to go
back and format the cell for, say, decimals.

HTH,
Bernie
MS Excel MVP

"Cindy" wrote in message
...
Can anyone tell me how to format a cell so that when a
date is entered it formats as a date and when a number is
entered it formats as a number.

If you use general it auto formats for a date but if you
enter a number in the same cell after a date has been
entered then it still thinks it's a date.

Any help will be appreciated.



  #3   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Format date and number

Thank you for your help.

-----Original Message-----
Cindy,

You're out of luck. To Excel, dates are numbers, and

numbers are numbers.
If you don't apply any formatting, Excel will format any

strings entered as
valid dates as dates, then convert them to the proper

number. Numbers it
will leave as"general".

So, enter your date as a valid date string, like

5/14/2004, and Excel will
know it is a date. However, once a cell ahs been

autoformatted as a date, it
will stay a date. If you want to do what you describe,

you do need to go
back and format the cell for, say, decimals.

HTH,
Bernie
MS Excel MVP

"Cindy" wrote in

message
...
Can anyone tell me how to format a cell so that when a
date is entered it formats as a date and when a number

is
entered it formats as a number.

If you use general it auto formats for a date but if

you
enter a number in the same cell after a date has been
entered then it still thinks it's a date.

Any help will be appreciated.



.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Format date and number

the previous poster is correct but... if you know the
dates or range of dates that will be entered you can use
this sub in the worksheet module to check and if it = one
of the dates leave as date otherwise format as general,
adapt it to your needs

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Const BD As Date = #1/1/2004#
Const ED As Date = #5/31/2004#
Dim num As Double
On Error GoTo EndSub
If Target.Value = BD And Target.Value <= ED Then
Target.NumberFormat = "m/d/yy"
Else
Target.NumberFormat = "General"
End If
EndSub:
End Sub



-----Original Message-----
Can anyone tell me how to format a cell so that when a
date is entered it formats as a date and when a number

is
entered it formats as a number.

If you use general it auto formats for a date but if you
enter a number in the same cell after a date has been
entered then it still thinks it's a date.

Any help will be appreciated.
.

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
Number format changes to date by itself Pillpshr Excel Discussion (Misc queries) 0 April 19th 10 09:36 PM
format number to date Picodillo Excel Worksheet Functions 8 July 21st 09 04:23 PM
How do you format a number into a date? Kim Excel Discussion (Misc queries) 6 September 12th 06 03:30 PM
* next to date format in Formatcells Number tab Marco18+ Excel Discussion (Misc queries) 6 April 5th 06 08:40 PM
Excel: I enter date and format for date, but shows as number spohar Excel Discussion (Misc queries) 2 March 10th 06 08:40 PM


All times are GMT +1. The time now is 07:48 AM.

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"