ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Returning a date from a UserForm (https://www.excelbanter.com/excel-programming/324938-returning-date-userform.html)

Black1

Returning a date from a UserForm
 
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...

Harald Staff

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...




Black1

Returning a date from a UserForm
 
Harald...

Thanks, that's exactly what I needed.


All times are GMT +1. The time now is 07:21 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com