vendredi 3 avril 2020

Why does my statement asking if two variables are equal not work?

Private Sub CommandButtonUndo_Click()

Dim Answer As Integer, LastRow As Variant, PreviousLastRow As Variant

LastRow = Worksheets("DATA").Range("A" & ActiveSheet.Rows.Count).End(xlUp).Row
PreviousLastRow = Names("PreviousLastRow").Value

If PreviousLastRow = LastRow Then
    MsgBox "Can only undo Once"
    Else
    If LastRow > 1 Then
        Answer = MsgBox("Are you sure you want to Undo the Previous Input?", vbYesNo + vbQuestion, "New Job")
            If Answer = vbYes Then
                Worksheets("DATA").Rows(LastRow).ClearContents
                Names("PreviousLastRow").Value = LastRow - 1
            End If   
    End If 
End If
End Sub

The idea of the code is to stop a user being able to click the undo button more than once. The specific part this is tripping me up is If PreviousLastRow = LastRow Then which just seems to be ignored and always follows the else path, even when I know the two variants are the same

Is this to do with the two numbers not being seen the same by the code?

Aucun commentaire:

Enregistrer un commentaire