View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Harald Staff Harald Staff is offline
external usenet poster
 
Posts: 1,327
Default Returning a date from a UserForm

Hi

Use Datevalue and you will be safe. Dates will be interpreted in the local
language and can be entered in any common way:

Private Sub CommandButton1_Click()
Dim D As Date
If IsDate(TextBox1.Text) Then
D = DateValue(TextBox1.Text)
Sheets(1).Range("B4").Value = D
Else
TextBox1.SelStart = 0
TextBox1.SelLength = Len(TextBox1.Text)
MsgBox "Invalid date entry"
End If
End Sub

HTH. Best wishes Harald

"Black1" skrev i melding
...
I've recently built an Excel based application for some of our staff and

have
now encountered a problem that I can't figure out.

A userform prompts the user to enter a date.. they enter it in the UK

format
(08/03/05 for 8th March), but the data posts to the underlying worksheet

as
03/08/05...and if we use dd-mmm-yy (on the sheet) it converts to

03-aug-05.

I obviously need to somehow define the format of the variable "xdate"

I can get round it by forcing it to accept the date as text, but this then
limits it's use.

I'd really appreciate your suggestions...