Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default 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...
  #2   Report Post  
Posted to microsoft.public.excel.programming
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...



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Returning a date from a UserForm

Harald...

Thanks, that's exactly what I needed.
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
Returning date instead of 'not null' Skeeterj Excel Worksheet Functions 4 November 3rd 09 04:40 PM
Formula for returning date entered by date on another worksheet Tom Excel Worksheet Functions 2 January 29th 09 05:44 AM
Date in userform being saved as general not date which affects sor Michael Malinsky[_3_] Excel Programming 0 July 28th 04 06:58 PM
Userform to select start date and end date Johnny B. Excel Programming 0 November 28th 03 05:56 PM
Returning a date as a serial umber David Excel Programming 1 November 3rd 03 09:30 AM


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