vbadatepowerpointdateadd

Powerpoint dateadd/date change subtraction


I have a variable (rptdate) that the user enters. I want to create a another variable (startdate) that is 7 days earler than the rptdate.

*I plan on using enddate also so that has been created below in addition to the other variables

Dim rptdate As Variant
Dim StartDate As Variant
Dim enddate As Variant

rptdate = InputBox("enter report date")
enddate = Format(rptdate, "mmmm d,yyyy")
StartDate = DateAdd(D, -7, enddate)

Solution

  • An InputBox always returns text, so try this:

    Dim rptInput  As String
    Dim rptDate   As Date
    Dim StartDate As String
    Dim EndDate   As String
    
    rptInput = InputBox("Enter report date")
    
    If IsDate(rptInput) Then
        rptDate = DateValue(rptInput)
        EndDate = Format(rptDate, "mmmm d, yyyy")
        StartDate = Format(DateAdd("d", -7, rptDate), "mmmm d, yyyy")
    End If