Delete the columns and formulas you added so your data looks like this:
---A---- ----B---- ----C----- ---D----
1 tran_amt post_date value_date drcr_trn
2 $- 20100423 20100423
3 $- 20100430 20100430
4 $12 20091230 20091230 C
5 $12 20091230 20091230 D
6 $14 20090519 20090519 C
7 $17 20090411 20090413 C
8 $20 20090713 20090713 C
9 $21 20100811 20100811 D
10 $24 20100907 20100907 D
11 $30 20100405 20100405 C
12 $30 20100518 20100518 C
13 $30 20100518 20100518 C
14 $31 20091104 20091104 C
(Actually that's what it looks like after it's sorted, which the code does.)
Then run DeleteMatchingTransactions
Option Explicit
Sub DeleteMatchingTransactions()
With Intersect(ActiveSheet.UsedRange, Columns("A:D"))
.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlYes
DeleteCells .Cells, "C", "D"
DeleteCells .Cells, "D", "C"
End With
End Sub
Sub DeleteCells(r As Range, s1 As String, s2 As String)
Dim rDel As Range
Dim iRow As Long
Dim iOfs As Long
For iRow = 1 To r.Rows.Count
With r(iRow, "A")
If .Offset(, 3).Value = s1 Then
iOfs = 1
Do
If .Offset(iOfs).Value = .Value Then
If .Offset(iOfs, 3).Value = s2 Then
If rDel Is Nothing Then
Set rDel = Union(.EntireRow, .Offset(iOfs).EntireRow)
Else
If Intersect(rDel, Rows(iRow)) Is Nothing Then
Set rDel = Union(rDel, .EntireRow, .Offset(iOfs).EntireRow)
End If
End If
Exit Do
Else
iOfs = iOfs + 1
End If
Else
Exit Do
End If
Loop
End If
End With
Next iRow
If Not rDel Is Nothing Then rDel.Delete
End Sub
That gets your 2914 rows down to 1364.
Forgive me, I don't have the time to address offsetting transactions that are sums of other transactions.
Bookmarks