VBA to compare 2 specific values in each row in two different sheets and highlight if match

dannyboi1

New Member
Joined
Jul 3, 2022
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi I am new to this board and have been trying to write this code to help my friend but having some struggles with this code

Essentially I'm trying to check if the invoice and fee on Sheet1 match the ones input on Sheet2, there are other columns as well, but they do not need to match, also the invoices aren't necessarily in the same order on both sheets

I'm having a tough time with once we're able to match invoice, check that the fee matches for that invoice, not sure if it's a double if statement or how to proceed

Hoping someone can please help with a code for this where I can than edit it with the specifics of the worksheet cause I am very lost

Thanks in advance :)
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
what columns have the invoice and the fee on sheet1, and what columns have the invoice and the fee on sheet2?

What kind of result do you want?

BTW you do not need VBA for this unless you need some kind of fancy report.
 
Upvote 0
what columns have the invoice and the fee on sheet1, and what columns have the invoice and the fee on sheet2?

What kind of result do you want?

BTW you do not need VBA for this unless you need some kind of fancy report.
For Sheet 1: Column B has Invoice and Column H has fee/expense
For Sheet 2: Column B has Invoice and Column I has fee/expense
Result: I'd say highlight the matches on Sheet 2

I thought VBA would be the best way about it, but if there's a better easier way, I'm open to it!
 
Upvote 0
In sheet2 use conditional formatting. Select all columns you want this apply to (entire columns) and add this conditional formatting rule:
Excel Formula:
=$I1=INDEX('Sheet 1'!$H:$H,MATCH($B1,'Sheet 1'!$B:$B,0))
with desired highlight formatting

Double check sheet names and update formula to match the actual sheet name if it is not "Sheet 1".

This will highlight rows in sheet 2 where the invoice number on sheet 1 has a different fee/expense than what is on sheet 2.

This assumes that Invoice in B is unique.
 
Upvote 0
Solution
In sheet2 use conditional formatting. Select all columns you want this apply to (entire columns) and add this conditional formatting rule:
Excel Formula:
=$I1=INDEX('Sheet 1'!$H:$H,MATCH($B1,'Sheet 1'!$B:$B,0))
with desired highlight formatting

Double check sheet names and update formula to match the actual sheet name if it is not "Sheet 1".

This will highlight rows in sheet 2 where the invoice number on sheet 1 has a different fee/expense than what is on sheet 2.

This assumes that Invoice in B is unique.
wow this was a lot easier than I was making it haha. And I was able to edit it to work exactly for my code - thank you so much for the help, I really appreciate it!!
 
Upvote 0

Forum statistics

Threads
1,214,639
Messages
6,120,679
Members
448,977
Latest member
dbonilla0331

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