Tips on searching and comparing multiple columns on separate sheets.
I am trying to write some code that will allow a user to compare data
columns from two separate sheets based on one or more key columns.
The first sheet comes from some laboratory instruments which generate
data associated with one or more columns making a unique key. The
second sheet is a scrubbed version of the first sheet to send to a
client. It also will have the key columns but their position may
vary. The goal is to make sure the second sheet's data columns match
those of the first.
There is a user form that allows one to select which columns on each
sheet represent the keys and which represent the data.
I currently am using several nested FOR loops which traverse through
each sheet to find the matching keys then compare the data columns.
Differences or duplicates are printed into a separate sheet for
reference.
One caveat is that I am not allowed to make changes to either source
or destination sheet.
Here is my algorithm:
For loop through each destination row
For loop through each source row
For loop through each key column
Compare key column
If key columns don't match then Exit For(go to next source
row)
For loop through each data column (All keys match)
Compare data columns and print problems
Next
Next
Next
Next
It works, but is quite inefficient.
Would there be any suggestions on how I might use any Excel built-in
functions, Range methods or such in order to improve the process?
Thank You!
|