Does what you want.
Finds first record where A<B and sets "a" as Col A value
When next row found where A<B, Col C shows "a-Col B value",
Resets "a" as new base value, and deducts that from third instance, then when next found, and so on.
Option Explicit
Dim a As Long, f As Long, j As Long, m As Long
Sub DIFFERENCES()
'Find last row with data
With Sheet1
f = .Cells(.Rows.Count, "A").End(xlUp).Row
For m = 2 To f
'If COl A < Col B
If .Cells(m, 1).Value < .Cells(m, 2).Value Then
j = j + 1
'If this is first instance, copy Col A value
If j = 1 Then
a = .Cells(m, 1).Value
'If this is second instance, Col C is Col A - Col B
ElseIf j = 2 Then
.Cells(m, 3).Value = a - .Cells(m, 2).Value
'Reset as first value in next pair
j = 1
a = .Cells(m, 1).Value
End If
End If
'Find next record
Next
End With
End Sub
Hope this helps
Ochimus
Bookmarks