Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default Handling dates in VBA

Hi

I have a userform where two dates are entered into some textboxes. In the
code these are processed a bit and should be returned to a sheet as
parameters in a query. The problem is, that they are returned as mm/dd/yyyy
and not dd/mm/yyyy as I need them. The code, that returns the values is:
....

Dim LowerDate, UpperDate As Date

intSpm = valSpm
....

With Sheets("DataAnswers")
With Range("UpperDate")
.Value = UpperDate
.NumberFormat = "d/m/yyyy"
End With
With Range("LowerDate")
.Value = LowerDate
.NumberFormat = "d/m/yyyy"
End With
.Range("Question").Value = intSpm
End With

The date 10-01-2007 (10th Jan, 2007) is returned as 01-10-2007 (1st Oct,
2007) whereas 26-06-2007 (26th Jun, 2007) is returned correctly.

What to do in Excel 2003, UK?!?

Thanks,

/Sune
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Handling dates in VBA

Hi Sune

Your problem is due to excel using american dates, you can fix this by
using the CDate function which is demonstrated below, if you need any
more info try searching for post on CDate by Tom Ogilvy he must have
around a million posts on this by now...

example code

Option Explicit

Dim UpperDate, LowerDate As Date

Private Sub CommandButton1_Click()

LowerDate = [a1].Value
UpperDate = [a2].Value

LowerDate = CDate(LowerDate)
UpperDate = CDate(UpperDate)

MsgBox LowerDate & vbNewLine & UpperDate

End Sub

hope this helps

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default Handling dates in VBA

Well, that was easy! I figured it woud be the American dates acting up, but
couldn't find the function to handle it.

Thank you very much for your help!

/Sune


"Incidental" wrote:

Hi Sune

Your problem is due to excel using american dates, you can fix this by
using the CDate function which is demonstrated below, if you need any
more info try searching for post on CDate by Tom Ogilvy he must have
around a million posts on this by now...

example code

Option Explicit

Dim UpperDate, LowerDate As Date

Private Sub CommandButton1_Click()

LowerDate = [a1].Value
UpperDate = [a2].Value

LowerDate = CDate(LowerDate)
UpperDate = CDate(UpperDate)

MsgBox LowerDate & vbNewLine & UpperDate

End Sub

hope this helps


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
Error Handling JLatham Excel Programming 2 March 24th 07 05:08 PM
error handling James Cornthwaite Excel Programming 2 June 7th 06 11:06 PM
Error handling. Francis Brown Excel Programming 3 December 1st 05 12:47 AM
Handling Dates in VLookup eager_beaver Excel Programming 21 July 25th 05 09:38 AM
Error handling with a handling routine ben Excel Programming 0 March 15th 05 03:01 PM


All times are GMT +1. The time now is 12:05 AM.

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"