+ Reply to Thread
Results 1 to 3 of 3

Date Formatting

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-24-2010
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2003
    Posts
    195

    Thumbs up Date Formatting

    Im having trouble with some error trapping code ive written for a range date Sub.
    Ive tagged the code in below. Basically Ive copied this piece of code from a previous Macro which uses the dd-mm-yy date format, but useing this same format within the new macro for me is is returning my "Invalid date format" error.

    Is there somthing I need to do within the VBA options to define the date formats accepted?
    Thanks in advance for your help!

    Sub RangeDate()
    
    If TextBox2.Value = "" Then
    MsgBox ("Enter start of Drawdown week")
    NoDate = True
    Exit Sub
    Else
    NoDate = False
    ThisWeekDate = TextBox1.Value
    End If
    
    If TextBox3.Value = "" Then
    MsgBox ("Enter end of Drawdown Week")
    NoDate = True
    Exit Sub
    Else
    NoDate = False
    ThisWeekDate = TextBox1.Value
    End If
    
    If Not (IsDate(TextBox1.Value) And IsDate(TextBox2.Value)) Then
    MsgBox "Invalid date format"
    NoDate = True
    Exit Sub
    ElseIf CDate(TextBox2.Value) <= CDate(TextBox1.Value) Then
    MsgBox ("Dates entered incorrectly")
    NoDate = True
    Exit Sub
    Else
    ThisWeekDate = TextBox2.Value
    End If
    
    End Sub

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Date Formatting

    I wouldn't use TextBoxes to enter dates, see the alternatives here
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Contributor
    Join Date
    02-24-2010
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2003
    Posts
    195

    Re: Date Formatting

    Thanks for that Roy, But Im afarid I have to stick with the text boxes for consistency reasons across the business I work in.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1