+ Reply to Thread
Results 1 to 4 of 4

Change Date with Date Picker If Date Less Than 7 Days From Another Date

Hybrid View

  1. #1
    Registered User
    Join Date
    08-30-2011
    Location
    Australia
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    57

    Change Date with Date Picker If Date Less Than 7 Days From Another Date

    I have a userform with 2 date pickers, The below code activates a message box if the date in dTpicker2 is greater than 6 days from DTpicker1, this works fine.

    I cannot get this macro to change the date via DTpicker 2 if the date is less than the 6 days, what do I have to add to make this happen, at the moment it will not change any date on sheet1 that is less than the 7 days.
    Private Sub DTpicker2_change()
    If DTPicker2 > DTPicker1.Value + 6 Then
    MSG1 = MsgBox("You Have Selected A Date Greater Than 7 Days, Do You Wish To Continue", vbYesNo, "Moving")
    If MSG1 = vbYes Then
    Sheets("Sheet1").Range("B1") = DTPicker2.Value
    Else
    If MSG1 = vbNo Then
    Exit Sub
    End If
    End If
    End If
    End Sub
    Thank for any assistance

  2. #2
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,645

    Re: Change Date with Date Picker If Date Less Than 7 Days From Another Date

    Hi there,

    I may have misunderstood your requirements, but see if the following code does what you need:

    
    
    Private Sub DTpicker2_change()
    
        Dim bUpdateCell As Boolean
        Dim iUserInput  As Integer
    
        bUpdateCell = True
    
        If DTPicker2.Value > DTPicker1.Value + 6 Then
    
            iUserInput = MsgBox("You Have Selected A Date Greater Than 7 Days, Do You Wish To Continue", vbYesNo, "Moving")
    
            If iUserInput <> vbYes Then
                bUpdateCell = False
            End If
    
        End If
    
        If bUpdateCell = True Then
            Sheets("Sheet1").Range("B1") = DTPicker2.Value
        End If
    
    End Sub

    Hope this helps - please let me know how you get on.

    Regards,

    Greg M

  3. #3
    Registered User
    Join Date
    08-30-2011
    Location
    Australia
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    57

    Re: Change Date with Date Picker If Date Less Than 7 Days From Another Date

    Thanks Greg M that works perfect, I will mark as solved.

  4. #4
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,645

    Re: Change Date with Date Picker If Date Less Than 7 Days From Another Date

    Hi again,

    Many thanks for your feedback.

    You're welcome - glad I was able to help.

    Regards,

    Greg M

+ 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. Replies: 0
    Last Post: 11-23-2015, 04:50 AM
  2. Date Picker to change date
    By mohansingh in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-20-2015, 09:43 AM
  3. Replies: 1
    Last Post: 05-26-2014, 03:46 AM
  4. Date Picker - can't change start date
    By JohnFex in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-30-2013, 04:05 PM
  5. Calculate date with a date picker + 8 days
    By sagar.rajula in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-10-2013, 03:40 PM
  6. I want any date 90 days or older from current date change color
    By Big Abalone in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 04-23-2006, 12:10 AM
  7. Replies: 3
    Last Post: 02-09-2006, 10:30 AM

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