Option Explicit
Sub Macro6()
'Matches reference numbers in column B where the amount for that reference number is initially positive
Dim lngEndRow As Long
Dim rngMyCell As Range
Dim rngMatchCell As Range
Application.ScreenUpdating = False
'Find the last row across columns A and B
lngEndRow = Range("A:B").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
'Sort the range by reference number (lowest to highest) and amount (highest to lowest)
'Range("A1:B" & lngEndRow).Sort key1:=Range("B1:B" & lngEndRow), order1:=xlAscending, Header:=xlNo, key2:=Range("A1:A" & lngEndRow), order2:=xlDescending, Header:=xlNo
For Each rngMyCell In Range("A1:A" & lngEndRow) 'Amount column
If Val(rngMyCell) > 0 And rngMyCell.Font.Bold = False And Len(rngMyCell) > 0 Then 'Only try and match the first reference if its amount is positive
For Each rngMatchCell In Range("A1:A" & lngEndRow)
If Val(Range("A" & rngMatchCell.Row)) * -1 = Val(Range("A" & rngMyCell.Row)) And Range("B" & rngMatchCell.Row) = Range("B" & rngMyCell.Row) Then
With Range("A" & rngMyCell.Row & ":B" & rngMyCell.Row)
.Copy Destination:=Range("C" & rngMyCell.Row)
.ClearContents
End With
With Range("A" & rngMatchCell.Row & ":B" & rngMatchCell.Row)
.Copy Destination:=Range("C" & rngMatchCell.Row)
.ClearContents
End With
Exit For
End If
Next rngMatchCell
ElseIf Val(rngMyCell) < 0 And Len(rngMyCell) > 0 Then
rngMyCell.Font.Bold = True
For Each rngMatchCell In Range("A1:A" & lngEndRow)
If Val(rngMatchCell) * -1 = Val(rngMyCell) And Range("B" & rngMatchCell.Row) = Range("B" & rngMyCell.Row) Then
rngMatchCell.Font.Bold = True
Exit For
End If
Next rngMatchCell
End If
Next rngMyCell
Application.ScreenUpdating = True
MsgBox "Done", vbInformation
End Sub