Comparing text files using Excel

181 views Asked by At

This is not a question about excel vba in particular. The question is what approach would be the best.

Here is the problem I have. I have 2 text files (one of current month and one for a prior month) that have account information as the first piece of information followed by other information that I am not concerned about. Here is an example. The information in bold is the account number and unfortunate for me, the records are not sorted i.e. the account numbers could be in any order

1030887-7 JAMES SMITH 12/15/13 03/05/13 212.50 180+

This kind of information exists in both files. I need to create a report of what is new in the current month file and what was carried over from the prior month. I am not concerned about any that was present in the prior month and not in the current.

I was thinking of reading one set of information into an array, sort and then begin reading the second one to start the comparison. Can anyone suggest a better method? The text files have almost 20000 lines in them.

I should mention that the text file I am trying to compare is a report and so has multiple headers, trailers etc and that is complicating the comparison. Also these accounts are by branch and I have to ensure that I don't mix 2 of them up. It seems to be doable but a little bit complex

1

There are 1 answers

0
rajah9 On

Instead of using Excel, I might suggest using a tool like diff. Please see Modern version of WinDiff? for a discussion.

(Win)Diff will perform a line-by-line comparison and tell you what lines are changed, deleted, or inserted.