Use index match to store and compare values between different sheets?

brewitbold

New Member
Joined
Oct 13, 2016
Messages
5
Hello,
Apologies if my post title is not the best summation of what I need. I am currently working with two different data sets that contain a unique identifier in column 8. This unique identifier is a concatenation of other fields within each row on each data set.

What I would like to do is perform an index-match in the second data set to find the corresponding value in data set one, and then determine if the value has changed between data set one and data set two. This could easily be accomplished without VBA if I only had 2 or 3 columns's worth of data to compare, but I need a solution that will scale up to to 30+ columns in future.

An example of the data from set one:
ID NOFirst NameLast NamePlan No.Plan NamePlan StatusStart DateUnique ID
123456798JTest141068104AApproved2/6/2016123456798141068104A42403
454629CJones549309401BDenied2/26/2016454629549309401B42426
344415QTest694742136CPending11/12/2016344415694742136C42675

<tbody>
</tbody>


An example of the data from set Two:
ID NOFirst NameLast NamePlan No.Plan NamePlan StatusStart DateUnique ID
123456798JTest141068104AApproved2/3/2016123456798141068104A42403
454629CJones549309401BDenied2/26/2016454629549309401B42426
344415QTest694742136CApproved11/12/016344415694742136C42675

<tbody>
</tbody>


Here is the snippet of code I am considering (here only set to compare changes in the first 7 columns, this will eventually change). The idea is that in the above examples, cell(4,6) of data set two would be highlighted in red.

I receive an error which is commented below, and I also don't receive the intended result. :confused: Any help is appreciated!!

Code:
For i = 2 To lastrow2
    For j = 1 To 7
    'Index match the unique ID on data set two to find corresponding value in data set one for each column in data set
        test = Application.WorksheetFunction.Index(dataSetOne, Application.WorksheetFunction.Match(dataSetTwo.Cells(i, 8), dataSetTwo.Range("h:h"), 0), j)
    
    'store the value of data set two for each cell
        test2 = dataSetTwo.Cells(i, j)
    
    'compare the values and highlight if they do not match
        If test <> test2 Then

    'this line is where I receive a "Object required" error
        test2.Interior.Color = RGB(255, 199, 206)
        End If
    
    Next
    
Next
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
brewitbold:

Here is a tested-working code. I tried to retain as much of your style as possible
for you to better understand the changes made. I hope you know how to define
your dataSetOne and dataSetTwo.

Code:
For i = 2 To lastrow2
    For j = 1 To 7
    'Index match the unique ID on data set two to find corresponding value in data set one for each column in data set
        test = dataSetOne.Cells(Application.WorksheetFunction.Match(dataSetTwo.Cells(i, 8).Value, dataSetOne.Range("H:H"), 0), j).Value
    
    'store the value of data set two for each cell
        test2 = dataSetTwo.Cells(i, j).Value
    
    'compare the values and highlight if they do not match
        If test <> test2 Then
            dataSetTwo.Cells(i, j).Interior.Color = RGB(255, 199, 206)
        End If
    Next
Next
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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