+ Reply to Thread
Results 1 to 4 of 4

testing if one date exceeds today's date by a specific number of days with vba

  1. #1
    Registered User
    Join Date
    05-30-2013
    Location
    Gaithersburg, MD
    MS-Off Ver
    Excel 2010
    Posts
    3

    testing if one date exceeds today's date by a specific number of days with vba

    I have created a userform to collect all of the information needed to order a logbook from our documentation department. One of the fields always writes the current date to the request, while the user can enter a "need by" date. the doc dept has asked for at least 4 days to process any new requests. What I am trying to do compare the two date to assure that the 4 day minimum is followed. Here is what I came up with:

    Private Sub TextBox11_Change()
    If CDate(TextBox11.Value) < Date + 4 Then
    MsgBox "Please allow at least 4 days to process your request."
    Exit Sub
    Else
    End If
    End Sub

    This works fine, but it leaves the selected date in TextBox11. So I inserted TextBox11.Text = "" between the MsgBox step and the Exit Sub step.

    Now I get a Type Mismatch error.pointing to the reset the TextBox11. How can I clear this value?

    thanks,
    Dana

  2. #2
    Valued Forum Contributor spitfireblue's Avatar
    Join Date
    01-29-2015
    Location
    Adelaide, Australia
    MS-Off Ver
    2007,2010,2016
    Posts
    611

    Re: testing if one date exceeds today's date by a specific number of days with vba

    Hi Dana,

    Your issue is that when you clear the text box the macro is restarting because the text box value changes. Therefore your first line of code doesn't work because it is comparing today's date to a null value.
    One way you could fix this is to add the following as your first line of code:

    Please Login or Register  to view this content.
    All the best,
    Stephen

  3. #3
    Registered User
    Join Date
    05-30-2013
    Location
    Gaithersburg, MD
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: testing if one date exceeds today's date by a specific number of days with vba

    That works perfectly! Thank you Stephen!

  4. #4
    Valued Forum Contributor spitfireblue's Avatar
    Join Date
    01-29-2015
    Location
    Adelaide, Australia
    MS-Off Ver
    2007,2010,2016
    Posts
    611

    Re: testing if one date exceeds today's date by a specific number of days with vba

    Glad I could help

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Calculate number of days between invoice date and today's date
    By JHerrick in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 04-30-2020, 03:53 PM
  2. [SOLVED] calculate number of days between a date and today
    By South texas man in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 02-20-2020, 04:58 PM
  3. Replies: 4
    Last Post: 02-28-2016, 06:09 PM
  4. [SOLVED] Clear userform if expiry date exceeds Today
    By bqheng in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-05-2015, 09:13 PM
  5. [SOLVED] Macros for: If Today's Date minus other date is greater than certain amount of days Then
    By lottidotti in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 10-24-2012, 04:46 PM
  6. Date color change if date exceeds 14 days
    By ayankinoz in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-26-2010, 11:45 PM
  7. create a macro to alert me if today's date is within 5 days of expected delivery date
    By ashmcclure in forum Excel Programming / VBA / Macros
    Replies: 25
    Last Post: 09-25-2008, 05:51 PM

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