The Code in Question
Option Explicit
Dim wsData As Worksheet
Dim wsResults As Worksheet
Dim rngData As Range
Dim custID As String
Dim amtOwed As Integer
Dim refData As Range
Dim refAns As Range
Dim noAns As Integer
Sub AmountOwed()
With wsData
Set rngData = .Range("A4", .Range("A10000").End(xlUp))
End With
For Each refData In rngData.Cells
amtOwed = refData.Offset(0, 1) - refData.Offset(0, 2)
If amtOwed > 1000 Then
custID = refData
refAns = custID
refAns.Offset(0, 1) = amtOwed
Set refAns = refAns.Offset(1, 0)
noAns = noAns + 1
End If
Next
With wsResults
.Range("A3").Resize(noAns, 2).Sort .Range("B4"), xlDescending, .Range("A4"), , xlAscending, , , xlYes
End With
End Sub