#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 27
Default Date format

Hi,

i created a form whereby user will input a date and on clicking the "OK"
button on the form, this date will be posted into a cell in excel. My problem
is, when it is posted in excel, the cell is not formatted as a date. I need
it to remain as a date so that i can make use of this cell to do other
calculations. Please help. The coding of my userform is as below:

Private Sub cmdOk_Click()

Dim ws As Worksheet
Set ws = Worksheets("FORM IR37")


'copy the data to form IR37
ws.Cells(20, 12).Value = Me.txtDate.Value


'clear the data
Me.txtDate.Value = ""
Me.txtDate.SetFocus

'close the form
Unload Me

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Date format

You may find that using a calendar control makes life easier.

See Ron de Bruin's site for more info:
http://www.rondebruin.nl/calendar.htm

But you could try:

Option Explicit
Private Sub cmdOk_Click()

Dim ws As Worksheet

Set ws = Worksheets("FORM IR37")

'copy the data to form IR37
If IsDate(Me.txtDate.Value) Then
With ws.Cells(20, 12)
.NumberFormat = "mmmm dd, yyyy"
.Value = CDate(Me.txtDate.Value)
End With
Unload Me
Else
'clear the data to start over???
Me.txtDate.Value = ""
Me.txtDate.SetFocus
End If
End Sub

But a user who enters
01/02/03
may be in for a suprise what date is used.



Dolphinv4 wrote:

Hi,

i created a form whereby user will input a date and on clicking the "OK"
button on the form, this date will be posted into a cell in excel. My problem
is, when it is posted in excel, the cell is not formatted as a date. I need
it to remain as a date so that i can make use of this cell to do other
calculations. Please help. The coding of my userform is as below:

Private Sub cmdOk_Click()

Dim ws As Worksheet
Set ws = Worksheets("FORM IR37")

'copy the data to form IR37
ws.Cells(20, 12).Value = Me.txtDate.Value

'clear the data
Me.txtDate.Value = ""
Me.txtDate.SetFocus

'close the form
Unload Me

End Sub


--

Dave Peterson
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
Convert date from text format to date format Anita Excel Discussion (Misc queries) 3 June 4th 07 11:57 AM
Convert date + time text format to date format Paul Ho Excel Worksheet Functions 2 May 22nd 07 05:47 PM
Can I change a date with no format (20051111) to date format? Rose New Users to Excel 2 November 11th 05 09:03 PM
day/month/year in incorrect format for date format M&A_Jack Excel Worksheet Functions 2 August 16th 05 08:15 PM
Excel 2000 date format cannot be set to Australian date format Brian Jones Excel Discussion (Misc queries) 1 March 30th 05 06:03 AM


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