Macro which highlights matching debits and credits?

Coyotex3

Well-known Member
Joined
Dec 12, 2021
Messages
507
Office Version
  1. 365
Platform
  1. Windows
Hello, I'm trying to get help with a macro that highlights matching debits and credits. I would like for the macro to go from this

Book1
ABC
1PropertyDebitCredit
2Central5000
3Central6000
4Central7000
5Central6000
6Central5000
7Central5000
8Central6000
9
10Central0600
11Central0700
12Central0600
13Central0500
14Central0500
15Central0700
16Central0800
Accounts


To this:

Book1
ABCD
1PropertyDebitCredit
2Central5000
3Central6000
4Central7000
5Central6000
6Central5000
7Central5000
8Central6000
9
10Central0600
11Central0700
12Central0600
13Central0500
14Central0500
15Central0700
16Central0800
17
Accounts
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Hello, according to your attachment a VBA demonstration for starters :​
VBA Code:
Sub Demo1()
        Dim L&, V, R&, W
    With Sheets("Accounts")
            L = .[A1].CurrentRegion.Rows.Count
            V = .Cells(L + 2, 1).CurrentRegion.Columns(3).Value2
        For R = 2 To L
                W = Application.Match(.Cells(R, 2).Value2, V, 0)
            If IsNumeric(W) Then
                Union(.Cells(R, 2), .Cells(L + W + 1, 3)).Interior.Color = vbYellow
                V(W, 1) = Empty
            End If
        Next
    End With
End Sub
 
Upvote 0
Solution
Hello, according to your attachment a VBA demonstration for starters :​
VBA Code:
Sub Demo1()
        Dim L&, V, R&, W
    With Sheets("Accounts")
            L = .[A1].CurrentRegion.Rows.Count
            V = .Cells(L + 2, 1).CurrentRegion.Columns(3).Value2
        For R = 2 To L
                W = Application.Match(.Cells(R, 2).Value2, V, 0)
            If IsNumeric(W) Then
                Union(.Cells(R, 2), .Cells(L + W + 1, 3)).Interior.Color = vbYellow
                V(W, 1) = Empty
            End If
        Next
    End With
End Sub
Thank you this is perfect. I ran into a slightly different form of data, is there a way of making it work on this:

Book1
ABC
1PropertyDebitCredit
2Central5000
3Central6000
4Central7000
5Central6000
6Central5000
7Central5000
8Central6000
9Central00
10Central0600
11Central0700
12Central0600
13Central0500
14Central0500
15Central0700
16Central0800
17Central01000
Accounts


To this:

Book1
ABC
1PropertyDebitCredit
2Central5000
3Central6000
4Central7000
5Central6000
6Central5000
7Central5000
8Central6000
9Central00
10Central0600
11Central0700
12Central0600
13Central0500
14Central0500
15Central0700
16Central0800
17Central01000
Accounts
 
Upvote 0
My VBA demonstration revamped :​
VBA Code:
Sub Demo1r()
        Dim V, W, R&, X
    With [Accounts!A1].CurrentRegion.Columns
           .Item("B:C").Interior.Pattern = xlNone
            V = .Item(2).Value2
            W = .Item(3).Value2
        For R = 2 To .Rows.Count
            If V(R, 1) Then
                X = Application.Match(V(R, 1), W, 0)
                If IsNumeric(X) Then Union(.Cells(R, 2), .Cells(X, 3)).Interior.Color = vbYellow: W(X, 1) = Empty
            End If
        Next
    End With
End Sub
 
Last edited:
Upvote 0
My VBA demonstration revamped :​
VBA Code:
Sub Demo1r()
        Dim V, W, R&, X
    With [Accounts!A1].CurrentRegion.Columns
           .Item("B:C").Interior.Pattern = xlNone
            V = .Item(2).Value2
            W = .Item(3).Value2
        For R = 2 To .Rows.Count
            If V(R, 1) Then
                X = Application.Match(V(R, 1), W, 0)
                If IsNumeric(X) Then Union(.Cells(R, 2), .Cells(X, 3)).Interior.Color = vbYellow: W(X, 1) = Empty
            End If
        Next
    End With
End Sub
Thank you mate! This was great as well, and worked as intended!
 
Upvote 0

Forum statistics

Threads
1,223,933
Messages
6,175,475
Members
452,646
Latest member
tudou

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top