VBA code for sorting and comparing two database lists.

mrzesty973

New Member
Joined
Jan 8, 2017
Messages
3
I have two databases that each have invoice numbers and invoice dates. I need code that will first sort each list of data in ascending order. Then I need the code to compare the lists from each database. The output of the code should show where each invoice data is matching or missing. If there is a match between the databases, the code should align the data on the same row. If the invoice is missing, the code should be able to write out "missing." There might be cases where the database themselves have duplicate data. In those cases, the duplicates should be listed down at the bottom of the database list. Please see the final output below.

Column A Column B Column D Column E
Database A Database B

Invoice # Due Date Invoice # Due Date
113565 12/15/2016 113565 12/15/2016
Missing Missing 113761 12/21/2016
140720513-001 11/14/2016 140720513-001 11/14/2016
140836272-002 8/9/2016 Missing Missing
140836272-003 7/15/2016 140836272-003 7/15/2016
Duplicate Data Duplicate Data
140720513-001 11/14/2016 113565 12/15/2016
113761 12/21/2016
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
mrzesty973,

Welcome to the MrExcel forum.


I would prefer not to have to separate your flat text display data into a worksheet.


We would like more information. Please see the Forum Use Guidelines in the following link:

http://www.mrexcel.com/forum/board-announcements/127080-guidelines-forum-use.html


See reply #2 at the next link, if you want to show small screenshots, of the raw data, and, what the results should look like.

http://www.mrexcel.com/forum/about-board/508133-attachments.html#post2507729


Or, you can post your workbook/worksheets to the following free site (sensitive data changed), mark the workbook for sharing, and, provide us with a link to your workbook:

https://dropbox.com
 
Last edited:
Upvote 0
Hi,

Please bare with me. I am new to the forum.

The dropbox link is https://www.dropbox.com/s/bkis8dsdkaydzbq/MrExcel Book 1.xlsx?dl=0. Not sure if this will work or not so I took a screen shot of the data.

Keep in mind that the data pasted below is just a guide to show the issue and desired solution. I would be ok with code that is developed using a different data set so long as it can generate the desired output. Right now I have to sort lists of data like this that are over a hundred invoices and I am doing it all manually using cut/paste. It takes me hours at times. I have searched around, and couldn't find anything close to what I need and its been years since I wrote sorting code.


Excel 2012
ABCDE
2Database A Raw DataDatabase B Raw Data
3Invoice NumberInvoice DateInvoice NumberInvoice Date
4140720513-00111/14/201611356512/15/2016
5140836272-0037/15/2016140720513-00111/14/2016
61096445/2/2016140836272-0037/15/2016
71096305/3/2016142218/9/2016
811376112/21/2016140836272-0028/9/2016
911356512/15/20161109437/12/2016
101096305/3/2016140720513-00111/14/2016
11140836272-0037/15/2016142218/9/2016
12
13
14Output of Sort/CompareOutput of Sort/Compare
15Invoice NumberInvoice DateInvoice NumberInvoice Date
1611376112/21/2016Missing
1711356512/15/201611356512/15/2016
18Missing142218/9/2016
191096305/3/2016Missing
201096445/2/2016Missing
21Missing1109437/12/2016
22140720513-00111/14/2016140720513-00111/14/2016
23Missing140836272-0028/9/2016
24140836272-0037/15/2016140836272-0037/15/2016
25
26Duplicate Data from Database ADuplicate Data from Database B
27Invoice NumberInvoice DateInvoice NumberInvoice Date
281096305/3/2016142218/9/2016
29140836272-0037/15/2016140720513-00111/14/2016
Sheet1
 
Upvote 0
mrzesty973,

Your screenshot in your reply #3 does not match the actual raw data (rows and columns), and, results, in your attached workbook?
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,399
Latest member
alchavar

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