Adding Date

  • Can anyone help me with the dateadd?

    User type in the date in mm/dd/yyyy format and it will compare with the data and display cells info on next page. Thanks.

    Dim lngBegin As Long, lngEnd As Long, lngCmp As Date, lngResults As Long
    lngBegin = 9 'beggining of data
    lngEnd = 232 'end of data
    lngCmp = InputBox("Please enter the date", "Begining of the week")

    lngcmp1 = DateAdd("d", 1, lngCmp)

    lngResults = 0
    lngResults1 = 0

    For I = lngBegin To lngEnd
    If lngCmp = Val(Cells(I, 31)) Then
    Sheets("Result").Cells(6 + lngResults, 3) = Sheets("Tracker2").Cells(I, 4)
    Sheets("Result").Cells(6 + lngResults, 4) = Sheets("Tracker2").Cells(I, 3)
    Sheets("Result").Cells(6 + lngResults, 5) = Sheets("Tracker2").Cells(I, 8)
    lngResults = lngResults + 1
    End If
    If DateValue(Lngcmp1) = Val(Cells(I, 31)) Then
    Sheets("Result").Cells(19 + lngResults1, 3) = Sheets("Tracker2").Cells(I, 4)
    Sheets("Result").Cells(19 + lngResults1, 4) = Sheets("Tracker2").Cells(I, 3)
    Sheets("Result").Cells(19 + lngResults1, 5) = Sheets("Tracker2").Cells(I, 8)
    lngResults1 = lngResults1 + 1
    lts5 = lngResults5 + 1
    End If
    MsgBox "Search Done"
    End Sub

  • Re: Adding Date

    A better way to select the date would be from a UserForm. When you go to insert a UserForm and bring up the Toolbox, right-click on it; and you'll see various options: DTPicker (date/time picker), MonthView, and Calendar.

    Using these, you prevent errors from Users.

    If you really must use an InputBox, try this:

    Then, I guess all you'd really do is need to compare your one variable (MonthGiven) to that of the other in the same format.

    Dim DateCompare$
    DateCompare = Sheets("Sheet2").Range("A12").value
    ' If DateCompare is a Date then compare MonthGiven in the same format to DateCompare
    If IsDate(DateCompare) = True and Format(MonthGiven, "mm/dd/yyyy") > Format(DateCompare, "mm/dd/yyyy") then
    ' do stuff
    End if

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!