ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Grouping like transactions (https://www.excelbanter.com/excel-programming/432001-grouping-like-transactions.html)

PVANS

Grouping like transactions
 
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


Per Jessen[_2_]

Grouping like transactions
 
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

On 4 Aug., 16:25, PVANS wrote:
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




All times are GMT +1. The time now is 04:06 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com