lundi 25 juin 2018

If statement not returning correct value in VBA

I am doing a date compare with ticket items, and if the ticket is closed it compares it to the close date. If ticket is still active it does the age to our current day. The code is skipping the if statement even if it is true. I made sure they are both strings while doing the compare. I have tried many things and can't seem to find out why. Any help would be awesome. Thanks!

Created = Rng.Column
Compare = Rng2.Column
Status = Rng3.Column
original = cells(i, Created)
Test = cells(i, Created)
Test2 = cells(i, Compare)

TestDate = CDate(Test)
TestDate2 = CDate(Test2)
cells(i, Created) = TestDate
cells(i, Compare) = TestDate2
CellStat = cells(i, Status)
Stuff = "Closed"

If CellStat = Stuff Then
    DDiff = cells(i, Compare) - cells(i, Created)
    Days = (Int(DDiff))
    ValHold = Days
    cells(i, Created) = ValHold
    cells(i, Created).Interior.ColorIndex = 3

Else
    DDiff = Now - cells(i, Created)

    Days = (Int(DDiff))
    ValHold = Days
    cells(i, Created) = ValHold

End If
i = i + 1

Loop

Aucun commentaire:

Enregistrer un commentaire