Excel VBA IF greater than or less than not working properly
<p>I'm trying to test if the old value of a cell is greater or less than the current value being inserted. However, it keeps saying it's neither.</p>

<p>I really have no idea why... Can anyone help me out?</p>

<pre><code>Dim oldCellValue As Integer
Dim curSheetName As String
Dim curCellAddress As String
Dim curCellValue As Integer

Public Sub Worksheet_SelectionChange(ByVal Target As Range)
    oldCellValue = Target.Value
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)

    curSheetName = ActiveSheet.Name
    curCellAddress = ActiveCell.Offset(-1, 0).Address
    curCellValue = ActiveCell.Offset(-1, 0).Value

    If oldCellValue = 0 And curCellValue = 0 Then
        Exit Sub
    Else

        With Application
            .ScreenUpdating = False
            .DisplayAlerts = False
            .EnableEvents = False
        End With

        Set Workbook = Workbooks.Open("stock.xlsx")

        If oldCellValue &gt; curCellValue Then
            Sheets(curSheetName).Range(curCellAddress) = ActiveCell.Value + (oldCellValue - curCellValue)
        ElseIf curCellValue &lt; oldCellValue Then
            Sheets(curSheetName).Range(curCellAddress) = ActiveCell.Value - (curCellValue - oldCellValue)
        Else
            MsgBox "Neither"
        End If

        Workbook.Save
        Workbook.Close

        With Application
            .ScreenUpdating = True
            .DisplayAlerts = True
            .EnableEvents = True
        End With

    End If

End Sub
</code></pre>

<p><strong>EDIT:</strong> I've updated the code with the suggestions and the fix, even though there's a new problem. See below comments.</p>

<pre><code>Dim oldCellValue As Integer
Dim curSheetName As String
Dim curCellAddress As String
Dim curCellValue As Integer

Public Sub Worksheet_SelectionChange(ByVal Target As Range)
    oldCellValue = Target.Value
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)

    curSheetName = ActiveSheet.Name
    curCellAddress = Target.Address
    curCellValue = Target.Value

    If oldCellValue = 0 And curCellValue = 0 Or oldCellValue = curCellValue Then
        Exit Sub
    Else

        With Application
            .ScreenUpdating = False
            .DisplayAlerts = False
            .EnableEvents = False
        End With

        Set Workbook = Workbooks.Open("stock.xlsx")

        If oldCellValue &gt; curCellValue Then
            Sheets(curSheetName).Range(curCellAddress) = ActiveCell.Value + (oldCellValue - curCellValue)
            MsgBox ActiveCell.Value
        Else
            Sheets(curSheetName).Range(curCellAddress) = ActiveCell.Value - (curCellValue - oldCellValue)
            MsgBox ActiveCell.Value
        End If

        Workbook.Save
        Workbook.Close

        With Application
            .ScreenUpdating = True
            .DisplayAlerts = True
            .EnableEvents = True
        End With

    End If

End Sub
</code></pre>