Macro to compare to worksheets and highlight new data

kcj784

New Member
Joined
Sep 20, 2012
Messages
1
I'm trying to create a macro that compares two excel worksheets and highlights the rows that are different. Basically, there is a sheet with rows of information. The first 3 columns contain various text that unique to that row of data. There could be a unique identifier for a row in all 3 columns or only one. The rest of the rows contain various info. Each day a report is run generating another sheet. Sometimes there are only one or two new rows of information. Let's say worksheet1 is the older sheet. I want to use search worksheet2 to see if it contains unique identifiers found in worksheet1. If it is found, move on to the next row. If it isn't found, that means the row of data is new and should be highlighted. Am I overlooking a simple way to do this? Thanks. :confused:
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Use application.match() on your primary key (unique key). Then use ifs to determine how to handle the cases.

On error resume next
For i = firstrow to lastrow
j = 0
j = application.match(sheets("sheet1").cells(i, 1).value), sheets("sheet2").columns(1), 0)
if j = 0 then _
sheets("Sheet1").cells(i, 1).interior.colorindex = 4
next j


Something like that would get you started, to look at each cell in sheet1, check sheet2 for a match, if there's no match color sheet1 cell red.
 
Upvote 0

Forum statistics

Threads
1,216,734
Messages
6,132,417
Members
449,727
Latest member
Aby2024

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