VBA Excel: procedure optimization find nonexisting values based on two sheets and reported in a Config Sheet

Hello experts,

I use the following Procedures to find non existing values based on two sheets and highlight them :

Sub DoIsNa(ResultRange As Range, ComparisonRange As Range)

Application.DisplayAlerts = False

Dim c As Range

For Each c In ResultRange
    If IsNumeric(Application.Match(c, ComparisonRange, 0)) Then
    Else: c.EntireRow.Interior.ColorIndex = "3"
    End If
Next c

Application.DisplayAlerts = True

End Sub

Sub RunIsNa()

Dim wb As Workbook
Dim ws1 As Worksheet

Set wb = ThisWorkbook
Set ws1 = wb.Sheets("Sheet1")
Set ws2 = wb.Sheets("Sheet2")

lastRows1 = ws1.UsedRange.Row - 1 + ws1.UsedRange.Rows.Count
lastRows2 = ws2.UsedRange.Row - 1 + ws2.UsedRange.Rows.Count

DoIsNa Range("Sheet1!A2:A" & lastRows1), Range("Sheet2!B2:B" & lastRows2)

End Sub

Open in new window

I would like to optimize the procedures by adding some requirements:

1-I would like to add a Config Sheet in order to dynamically use this procedures based on the information reported in Config Sheet:
ResultRangeSheet: In this sheet I will report all the values (highlight the values) which are not in ComparisonRangeSheet.

ComparisonRangeSheet: This is the reference sheet, based on this I will report the values which don't exist in ResultRangeSheet

DestinationResultSheet: In this sheet I need to report the various lines which are not in ResultRangeSheet highlighted in Red.

ResultKey: Is the column letter related to my key to compare.

ComparisonKey: Is the column letter related to my key reference.

Ex:ResultKey:B and ComparisonKey:C. I need to compare all the values reported in column B of ResultRangeSheet which are not in values reported in columns C of ComparisonRangeSheet.

2-I would also like to report concatenated key columns.

Ex: If I report for ResultKey C&E and ComparisonKey A&B the keys values will be composed by the concatenation of C&E and A&B. If this concatenation way is not the best way to report in ConfigSheet, I am in to change it.

3-My previous macro just highlight all the isna values I will like to highlight the values but also report them based on the Config Sheet DestinationResultSheet.

Please find attached a sample of I want.

Thank you very much for your help for your help.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ejgil HedegaardCommented:
Try attached workbook.
With 2 columns to match it is not possible to use the match function.
The program loads the ranges into arrays, and concatenate if needed.
Then loops the arrays to check for match.
It is much faster to load the ranges to arrays and loop the arrays, than reading the values on the sheet for every check.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LD16Author Commented:
Perfect! It works as always, thank you again for your help!

I have two short remarks:

1-Is there a way to count the number of ISNA rows and Key rows  related to every config reported row like this:

2-The concatenation is blocked to just 2 columns is not a way to have a concatenation of 3 columns or more. If not possible just 2 or 3 columns?

I am really sorry for not specifying this from the beginning. If you prefer I open a new question related to those 2 remarks.

Thank you again for your help.
Ejgil HedegaardCommented:
1: That is quite easy to do, the values are known.
RowsKey N is number of data rows on ResultRangeSheet, and ISNA N is number of not matched rows (= rows on DestinationRangeSheet)

2: I have an idea of how to do that, perhaps with an unlimited number of columns.
But it requires a new approach to the way data are collected before compare.

It will take a couple of days, because it is late now, and I don't have time to do anything tomorrow.

Yes, I think you should mark this as solved, and open a new question.
Besides that the question does not show on Open questions any more, strange!
LD16Author Commented:
Noted! Thank you very much!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.