Compare, Match and Copy based upon 2 variables

goobee

New Member
Joined
Feb 25, 2011
Messages
26
We are looking for an easier way to automate matching payments from customers. Checks that include invoice numbers are easily matched, those are not the problem. It is for the payments that are received without invoice numbers that require manual review to determine where the money should be allocated to.

Below, I've included 2 sample tables, one that contains the orders and another that contains the payments received. Although Customers Numbers are common on both tables, simply matching the Customer Numbers do not work as customers can have more than one order and can have more than one check received. (Tried using Vlookup which did not work due to multiple instances of Customer Numbers and multiple instances of same dollar values. Index & Match didn't work either)

Ideally, we would a macro that can do these things:


  • Compare and match Customer Numbers
  • If Customer Number match is found, compare and match dollar amounts
  • If dollar matches found, copy Check Amounts and Check Numbers to output report (see output report)
  • If no matches found, enter "Not Found"

I imagine this may be too complicated for macro to handle but it doesn't hurt to ask.

Thanks in advance.

Customer Orders Table

Customer NoInvoice NumberPurchase Amount
1593507213588-1 5,000.00
14255909559387-1 3,500.00
18573509592476-1 8,581.00
19689907355651-1 9,200.00
27957901001349-1 6,568.77
31938108928126-1 3,500.00
34979706677269-1 100.00
34979706677269-1 100.00
34979706677269-1 100,000.00
35092704169385-1 3,500.00
35092704169385-1 3,500.00
41976408927751-1 15,000.00
42144306764633-1 1,500.00
43684009015276-1 3,500.00
43846309016534-1 3,500.00
47194809041007-1 5,000.00
48133009048932-1 5,000.00
49339102331161-1 5,000.00
52632003359918-1 3,500.00
52632003359918-1 3,510.00
54550203316973-1 75,000.00
57977803636433-1 3,500.00
58319906887036-1 3,500.00
58319906887036-1 3,500.00
60682307664043-1 4,500.00
62027004429721-1 5,000.00
62027004429721-1 7,631.20
63354204442762-1 7,500.00
73796007761962-1 406.00
77953203898704-1 2,000.00
88396007871511-1 3,500.00
94145709396825-1 7,500.00
96167509411797-1 611.40
97016807936233-1 3,500.00
97175008673382-1 9,000.00
97432509422044-1 7,500.00
97432509422044-1 7,500.00

<tbody>
</tbody>

Payments Received Table

Customer NoCheck AmountCheck Number
15935 5,000.00104727370
21128 1,250.00119204419
21128 1,450.00145930023
109225 10,235.00147330779
128912 6,533.00145558906
142559 3,500.00142946325
185735 8,581.00146842182
196899 9,200.00137189591
279579 6,568.77148727437
306326 25,000.00147166738
319381 3,500.00145927908
349797 100.00142446881
349797 100.00142446882
349797 100,000.00147747165
350927 3,500.00130843967
350927 3,500.00147096693
419764 15,000.00123466494
421443 1,500.00100599091
436840 3,500.00134345889
437252 1,500.00139573296
438463 3,500.00145734790
452126 4,500.00147099095
471948 5,000.00144172551
481330 5,000.00131034064
493391 5,000.00128081007
526320 3,500.00123845749
540944 250,000.00149143010
545502 75,000.00144259893
547478 9,253.00132728054
583199 3,500.00130042365
583199 3,500.00142366423
605244 35,000.00145650826
605244 7,500.00146085435
606823 4,500.00124372621
620270 5,000.00143212783
633542 7,500.00143804189
656817 7,500.00125486623
700698 1,500.00143981597
737960 406.00129955189
779532 2,000.00147098652
815124 9,253.00146586643
883960 3,500.00144992649
930482 35,000.00148813121
941457 7,500.00109629786
947913 7,500.00117616433
947913 7,500.00145157309
961675 611.40147942078
970168 3,500.00141559228
974325 7,500.00145156081

<tbody>
</tbody>

Output Report Example

Customer NoInvoice NumberInvoice NumberPurchase AmountCheck AmountCheck Number
1593507213588-107213588-1 5,000.00 5,000.00104727370
14255909559387-109559387-1 3,500.00 3,500.00142946325
18573509592476-109592476-1 8,581.00 8,581.00146842182
19689907355651-107355651-1 9,200.00 9,200.00137189591
27957901001349-101001349-1 6,568.77 6,568.77148727437
31938108928126-108928126-1 3,500.00 3,500.00145927908
34979706677269-106677269-1 100.00 100.00142446881
34979706677269-106677269-1 100.00 100.00142446882
34979706677269-106677269-1 100,000.00 100,000.00147747165
35092704169385-104169385-1 3,500.00 3,500.00130843967
35092704169385-104169385-1 3,500.00 3,500.00147096693
41976408927751-108927751-1 15,000.00 15,000.00123466494
42144306764633-106764633-1 1,500.00 1,500.00100599091
43684009015276-109015276-1 3,500.00 3,500.00134345889
43846309016534-109016534-1 3,500.00 3,500.00145734790
47194809041007-109041007-1 5,000.00 5,000.00144172551
48133009048932-109048932-1 5,000.00 5,000.00131034064
49339102331161-102331161-1 5,000.00 5,000.00128081007
52632003359918-103359918-1 3,500.00 3,500.00123845749
52632003359918-103359918-1 3,500.00 Not FoundNot Found
54550203316973-103316973-1 75,000.00 75,000.00144259893
57977803636433-103636433-1 3,500.00 Not FoundNot Found
58319906887036-106887036-1 3,500.00 3,500.00130042365
58319906887036-106887036-1 3,500.00 3,500.00142366423
60682307664043-107664043-1 4,500.00 4,500.00124372621
62027004429721-104429721-1 5,000.00 5,000.00143212783
62027004429721-104429721-1 5,000.00 Not FoundNot Found
63354204442762-104442762-1 7,500.00 7,500.00143804189
73796007761962-107761962-1 406.00 406.00129955189
77953203898704-103898704-1 2,000.00 2,000.00147098652
88396007871511-107871511-1 3,500.00 3,500.00144992649
94145709396825-109396825-1 7,500.00 7,500.00109629786
96167509411797-109411797-1 611.40 611.40147942078
97016807936233-107936233-1 3,500.00 3,500.00141559228
97175008673382-108673382-1 3,500.00 Not FoundNot Found
97432509422044-109422044-1 7,500.00 7,500.00145156081
97432509422044-109422044-1 7,500.00 Not FoundNot Found

<tbody>
</tbody>
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Using Power Query/Get and Transform. Upload each table to PQ. Close and Load to a Connection. Merge the two tables as shown in the following Mcode.

Code:
let
    Source = Table.NestedJoin(Payments, {"Check Amount", "Customer No"}, Invoices, {"Purchase Amount", "Customer No"}, "Invoices", JoinKind.LeftOuter),
    #"Expanded Invoices" = Table.ExpandTableColumn(Source, "Invoices", {"Invoice Number", "Purchase Amount"}, {"Invoices.Invoice Number", "Invoices.Purchase Amount"})
in
    #"Expanded Invoices"

Data Range
A
B
C
D
E
1
Customer No​
Check Amount​
Check Number​
Invoices.Invoice Number​
Invoices.Purchase Amount​
2
15935​
5000​
104727370​
07213588-1​
5000​
3
21128​
1250​
119204419​
4
142559​
3500​
142946325​
09559387-1​
3500​
5
21128​
1450​
145930023​
6
185735​
8581​
146842182​
09592476-1​
8581​
7
109225​
10235​
147330779​
8
196899​
9200​
137189591​
07355651-1​
9200​
9
128912​
6533​
145558906​
10
279579​
6568.77​
148727437​
01001349-1​
6568.77​
11
319381​
3500​
145927908​
08928126-1​
3500​
12
349797​
100​
142446881​
06677269-1​
100​
13
349797​
100​
142446881​
06677269-1​
100​
14
349797​
100​
142446882​
06677269-1​
100​
15
349797​
100​
142446882​
06677269-1​
100​
16
349797​
100000​
147747165​
06677269-1​
100000​
17
306326​
25000​
147166738​
18
350927​
3500​
130843967​
04169385-1​
3500​
19
350927​
3500​
130843967​
04169385-1​
3500​
20
350927​
3500​
147096693​
04169385-1​
3500​
21
350927​
3500​
147096693​
04169385-1​
3500​
22
419764​
15000​
123466494​
08927751-1​
15000​
23
421443​
1500​
100599091​
06764633-1​
1500​
24
436840​
3500​
134345889​
09015276-1​
3500​
25
438463​
3500​
145734790​
09016534-1​
3500​
26
471948​
5000​
144172551​
09041007-1​
5000​
27
481330​
5000​
131034064​
09048932-1​
5000​
28
493391​
5000​
128081007​
02331161-1​
5000​
29
526320​
3500​
123845749​
03359918-1​
3500​
30
437252​
1500​
139573296​
31
545502​
75000​
144259893​
03316973-1​
75000​
32
452126​
4500​
147099095​
33
583199​
3500​
130042365​
06887036-1​
3500​
34
583199​
3500​
130042365​
06887036-1​
3500​
35
583199​
3500​
142366423​
06887036-1​
3500​
36
583199​
3500​
142366423​
06887036-1​
3500​
37
606823​
4500​
124372621​
07664043-1​
4500​
38
620270​
5000​
143212783​
04429721-1​
5000​
39
540944​
250000​
149143010​
40
633542​
7500​
143804189​
04442762-1​
7500​
41
547478​
9253​
132728054​
42
605244​
35000​
145650826​
43
605244​
7500​
146085435​
44
656817​
7500​
125486623​
45
700698​
1500​
143981597​
46
737960​
406​
129955189​
07761962-1​
406​
47
779532​
2000​
147098652​
03898704-1​
2000​
48
815124​
9253​
146586643​
49
883960​
3500​
144992649​
07871511-1​
3500​
50
930482​
35000​
148813121​
51
941457​
7500​
109629786​
09396825-1​
7500​
52
947913​
7500​
117616433​
53
947913​
7500​
145157309​
54
961675​
611.4​
147942078​
09411797-1​
611.4​
55
970168​
3500​
141559228​
07936233-1​
3500​
56
974325​
7500​
145156081​
09422044-1​
7500​
57
974325​
7500​
145156081​
09422044-1​
7500​
 
Last edited:
Upvote 0
How about
Code:
Sub goobee()
    Dim OrdAry As Variant, PayAry As Variant
    Dim i As Long, j As Long
    
    With Sheets("Sheet1")
        OrdAry = .Range("A1").CurrentRegion.Resize(, 5).Value2
    End With
    With Sheets("Sheet3")
        PayAry = .Range("A1").CurrentRegion.Value2
    End With
    For i = 2 To UBound(OrdAry)
        For j = 2 To UBound(PayAry)
            If OrdAry(i, 1) = PayAry(j, 1) And OrdAry(i, 3) = PayAry(j, 2) Then
                OrdAry(i, 4) = PayAry(j, 2)
                OrdAry(i, 5) = PayAry(j, 3)
                PayAry(j, 1) = ""
                Exit For
            End If
        Next j
    Next i
    Sheets("Sheet1").Range("A1").CurrentRegion.Resize(UBound(OrdAry), 5).Value2 = OrdAry
End Sub
Change sheet names to suit
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,744
Members
448,989
Latest member
mariah3

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