I have a simple workbook (see attached) with code as below.

[VBA]
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
If Target.Column <> 1 Or Target.Row = 1 Or Target.Row = 2 _
Or Target.Value = "" Then Exit Sub

If Err.Number = 2015 Then Exit Sub

Dim PR As Integer

PR = ActiveSheet.Cells(Target.Row, 1).End(xlUp).Row

ActiveSheet.Cells(Target.Row - 1, 7).Formula = _
"=B" & PR & "-Sum(F" & PR & ":F" & Target.Row - 1 & ")"
End Sub
[/VBA]

The macro does the following in G. When the user inputs a value in A the macro sums the previous values in F and subtracts from the previous value in B.

In this example G3 would be B2 minus sum of F2+F3.
G4 would be B4 minus F4.
G5 would be B5 minus F5.

As you can see in the attached all works well until there are consecutive single value entries in F.

Any ideas how to fix this problem? Thanks in advance.