Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Preserving date format in VB

I have some code which checks the entry in a cell is a date and prompts the
user for a date if it's not:

Dim ADate
Dim Message, Title, Default
Message = "Enter the date as d/m/yy"
Title = "Date Format"
Default = "25/12/07"
Worksheets("Summary").Range("E4").Activate
ActiveCell.NumberFormat = "d/m/yy"
ADate = ActiveCell
Do Until IsDate(ADate)
' Display message, title, and default value.
ADate = InputBox(Message, Title, Default)
ActiveCell.Value = ADate
Loop
ActiveCell.NumberFormat = "d mmmm yyyy"

The trouble is, if as the user, I input 1/8/07 (in place of "1st Aug 07"),
it returns the US format. ie 8 January 2007.
Can anyone help to correct this, please?

Apologies if you recognise any of the code - it is plagiarised from this site.
Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Preserving date format in VB

Try this

Dim ADate
Dim Message, Title, Default
Message = "Enter the date as d/m/yy"
Title = "Date Format"
Default = "25/12/07"
Worksheets("Summary").Range("E4").Activate
ActiveCell.NumberFormat = "d/m/yy"
ADate = ActiveCell
Do Until IsDate(ADate)
' Display message, title, and default value.
ADate = InputBox(Message, Title, Default)
ActiveCell.Value = CDate(ADate)
Loop
ActiveCell.NumberFormat = "d mmmm yyyy"


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Jimbob" wrote in message
...
I have some code which checks the entry in a cell is a date and prompts the
user for a date if it's not:

Dim ADate
Dim Message, Title, Default
Message = "Enter the date as d/m/yy"
Title = "Date Format"
Default = "25/12/07"
Worksheets("Summary").Range("E4").Activate
ActiveCell.NumberFormat = "d/m/yy"
ADate = ActiveCell
Do Until IsDate(ADate)
' Display message, title, and default value.
ADate = InputBox(Message, Title, Default)
ActiveCell.Value = ADate
Loop
ActiveCell.NumberFormat = "d mmmm yyyy"

The trouble is, if as the user, I input 1/8/07 (in place of "1st Aug 07"),
it returns the US format. ie 8 January 2007.
Can anyone help to correct this, please?

Apologies if you recognise any of the code - it is plagiarised from this
site.
Thanks



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Preserving date format in VB

Jimbob,

try replacing this line:

ActiveCell.Value = ADate

with this:

ActiveCell.Value = CDate(Format(ADate, "dd/mm/yyyy"))


--
Hope that helps.

Vergel Adriano


"Jimbob" wrote:

I have some code which checks the entry in a cell is a date and prompts the
user for a date if it's not:

Dim ADate
Dim Message, Title, Default
Message = "Enter the date as d/m/yy"
Title = "Date Format"
Default = "25/12/07"
Worksheets("Summary").Range("E4").Activate
ActiveCell.NumberFormat = "d/m/yy"
ADate = ActiveCell
Do Until IsDate(ADate)
' Display message, title, and default value.
ADate = InputBox(Message, Title, Default)
ActiveCell.Value = ADate
Loop
ActiveCell.NumberFormat = "d mmmm yyyy"

The trouble is, if as the user, I input 1/8/07 (in place of "1st Aug 07"),
it returns the US format. ie 8 January 2007.
Can anyone help to correct this, please?

Apologies if you recognise any of the code - it is plagiarised from this site.
Thanks

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Preserving date format in VB

Bob, What a star you are!
Fabulous - works a treat.

Thank you so much

"Bob Phillips" wrote:

Try this

Dim ADate
Dim Message, Title, Default
Message = "Enter the date as d/m/yy"
Title = "Date Format"
Default = "25/12/07"
Worksheets("Summary").Range("E4").Activate
ActiveCell.NumberFormat = "d/m/yy"
ADate = ActiveCell
Do Until IsDate(ADate)
' Display message, title, and default value.
ADate = InputBox(Message, Title, Default)
ActiveCell.Value = CDate(ADate)
Loop
ActiveCell.NumberFormat = "d mmmm yyyy"


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Jimbob" wrote in message
...
I have some code which checks the entry in a cell is a date and prompts the
user for a date if it's not:

Dim ADate
Dim Message, Title, Default
Message = "Enter the date as d/m/yy"
Title = "Date Format"
Default = "25/12/07"
Worksheets("Summary").Range("E4").Activate
ActiveCell.NumberFormat = "d/m/yy"
ADate = ActiveCell
Do Until IsDate(ADate)
' Display message, title, and default value.
ADate = InputBox(Message, Title, Default)
ActiveCell.Value = ADate
Loop
ActiveCell.NumberFormat = "d mmmm yyyy"

The trouble is, if as the user, I input 1/8/07 (in place of "1st Aug 07"),
it returns the US format. ie 8 January 2007.
Can anyone help to correct this, please?

Apologies if you recognise any of the code - it is plagiarised from this
site.
Thanks




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
Preserving date format Julia862621 Excel Discussion (Misc queries) 1 May 11th 10 03:17 PM
Fill a combobox preserving characters format [email protected] Excel Programming 1 April 12th 07 02:45 AM
preserving cell format bob777 Excel Discussion (Misc queries) 2 November 4th 05 12:53 PM
preserving format in a formula exceldoofus Excel Worksheet Functions 3 October 12th 05 06:27 PM
preserving cell format between linked documents lyriamoonriver Excel Discussion (Misc queries) 1 May 17th 05 08:53 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"