Grouping like transactions

P

PVANS

Good afternoon

I am working with an excel workbook that lists 100+ transactions. I have
managed to write a macro that looks at the transactions row by row, assessing
two criteria (column B, and column D), and leaving a few blank lines between
the different rows if either column B or Column D are different to the
transaction above.

However, there are transactions at various points throughout the workbook
that have matching criteria in terms of Column B and D. Is there a macro, or
could someone help me write a macro, that will look through the entire
workbook, find all transactions that have matching values in terms of Column
B and D, and group those transactions together? In other words, a method to
sort the rows in terms of values in Column B and D?

(btw, in case it matters, column B and column D are both text fields)

I really would appreciate any advise or suggestions

Thanks in anticipation

Regards
 
P

Per Jessen

Hi

Try this:

Sub AAA()
Dim LastRow As Long
Dim SortRange As Range

LastRow = Range("A" & Rows.Count).End(xlUp).Row
Set SortRange = Range("A1:F" & LastRow) ' Change column reference as
needed
SortRange.Sort Key1:=Range("B2"), Order1:=xlAscending, Key2:=Range
("D2") _
, Order2:=xlAscending, Header:=xlYes, OrderCustom:=1, MatchCase:=
_
False, Orientation:=xlTopToBottom

For r = LastRow To 3 Step -1
If Cells(r, 2) <> Cells(r - 1, 2) Or Cells(r, 4) <> Cells(r - 1,
4) Then
Rows(r).EntireRow.Insert
End If
Next
End Sub

Regards,
Per
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top