mardi 16 janvier 2018

Use IF Statement to compare variable to stored date

I am trying to run a loop of my data that checks a number of different aspects, and if any fail, the macro deletes the row. I have everything working except for the check of the date. If a date in a given cell is equal to the date input initially, I want to keep the row, otherwise I want to delete it. However I cant seem to get my date compare to work. Any thoughts?

Dim myValue As Variant
myValue = InputBox("Enter current as of date (MM/DD/YY)")

Dim dDate As Date
Dim NumberofRows As Long
Dim x As Long

With Worksheets("Transactions")
    NumberofRows = .Cells(.Rows.Count, "C").End(xlUp).Row

    For x = 1 To NumberofRows
        If (.Range("Q" & x).Value) = myValue.Date Then                     ActiveCell.Offset(1, 0).Select


            Else
                ActiveCell.EntireRow.Select
                Selection.Delete
                Range("A" & (ActiveCell.Row)).Select
        End If
    Next x

End With

Aucun commentaire:

Enregistrer un commentaire