See attached file.
Click the "Run" button and column B and C will list cell references for two consecutive non-zero values in column A.
Column d will have the difference.
here's the simple macro:
Sub subtraction()
Dim lr, x, y As Long
Dim value1, value2 As Long
With Worksheets("Sheet1")
lr = .Range("A" & Rows.Count).End(xlUp).Row
End With
y = 1
With ActiveSheet
For x = 1 To lr
If .Range("A" & x).Value > 0 Then
If value1 > 0 Then
.Range("B" & y).Value = "A" & x
value2 = .Range("A" & x).Value
Else: value1 = .Range("A" & x).Value
.Range("C" & y).Value = "A" & x
End If
If value2 > 0 Then
.Range("D" & y).Value = value2 - value1
y = y + 1
value1 = 0
value2 = 0
End If
End If
Next x
End With
End Sub
Bookmarks