I need to write VB macro in Excel that would compare data in two columns within the same spreadsheet and highlight the row in red if the data is different. Please see attached a sample file. The two columns that I need to compare are "A" and "D".
How do you expand the range for conditional format?
Steve Bez
ASKER
Never mind, I found it. Let me test it out.
Rob Henson
In the conditional format rules window, to the right of each rule is a range selector tool. Simply click that and highlight the range to which the rule needs applying or type it in manually.
The one thing to remember is that the row referred to in the rule has to be the first row of the range. In this instance the rule states:
=$A2<>$D2
Therefore the Applies to range has to start at row 2 otherwise the format will be offset.
The conditional formatting works well when there are no exceptions. As I just found out the following type of exception is possible in the future. For example, if two or more records, see below, have the same "Name.ID:" then dollar amount in column "A" for those two or more records needs to be added together and compared to dollar amount in column "D" for the first record with the same ID. If total is the same then we are good, otherwise we highlight.
Ok, the rule would have to include a SUMIF function rather than a direct one to one comparison. Not at PC at the minute.
Shums Faruk
Hi Steve,
Please find attached... I have added helper column which will determine What needs reconciliation and highlights the text. Doesn't matter how long your data would be. Reconcil-03-16-17-v1.xlsm
Thanks a lot for a quick response! If you could change the macro a bit so if it's the same "Name.ID" for two or more records then it shouldn't be errored out. See attached spreadsheet.
As you can see in attached spreadsheet, the first two rows after column name, have the same "Name.ID", which is 1012926, and when we add two amounts in column "A", which is $135.00 and $575.00, then we get $710 which is correct amount reflected in column "D".
In this situation, we don't want to error out anything. Same applies to row 4 and 5 since those have the same "Name.ID" as well.
Now, row 6 and 7 have the same "Name.ID" but a different sum when you add the amounts in column "A" and compare it to the number at column "D" row 6.
Another discrepancy is in row 8 where there is only one record but amounts are not matching because column "D" is blank.
Those are the scenarios for now. Also, there maybe 3 records with the same "Name.ID" so we need to calculate amount for all of them and compare to column "D". Out of those three records the first one always as the total in column "D".
I know that's a lot of explanation. Sorry... Book1.xlsx
Steve Bez
ASKER
Hi Rob,
thanks for your response. your original solution worked well, it just needs to be enhanced. i'll wait for your response back.
Thanks Rob! Very nice and concise solution but would require an extra step in specifying how many rows to process, so I'm gonna go ahead with Shums's solution.
You can use Conditional Formatting for this.
See attached, I have changed the value in D3 to show the highlight in work.