Updating Existing Code That Highlights Discrepancies

Jambi46n2

Active Member
Joined
May 24, 2016
Messages
260
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have an existing code I use that works nicely.

Basically if I have two "identical" sheets. Lets say Sheet 1 and Sheet 2.

Sheet 1 may have a cell missing data that doesn't match the same area in Sheet 2.

This code will compare both sheets on a cell level,
then highlight the discrepancies with a message box letting you know how many discrepancies there are.

The only problem I have with this code, is if a row is missing it will highlight everything below that row as a discrepancy.

Is there a way to make this code check for missing rows as well?

Thank you!

Code:
Sub QC_Check()

If MsgBox("Highlight Discrepancies Between Sheet1 and Sheet2?", vbYesNo) = vbNo Then Exit Sub
    
'Check For Discrepancies and Highlight
' C is Cell Comparison
' Solve for X to identify discrepancies

    Dim x As Long
    x = 0
    Dim c As Range


    Sheets(1).Select
    Cells.Select
    Selection.Columns.AutoFit
    With Selection.Interior
        .Pattern = xlNone
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    
    Sheets(2).Select
    Cells.Select
    Selection.Columns.AutoFit
    With Selection.Interior
        .Pattern = xlNone
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    
    Sheets(1).Select


    For Each c In Sheets(1).UsedRange
        If c.Text <> Sheets(2).Range(c.Address).Text Then
            c.Interior.Color = vbYellow
            x = x + 1
        End If
    Next c


MsgBox "There Are " & x & " Discrepancies"
 
Last edited:

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
How about just using a conditional format?

=IF(Sheet1!A1<>Sheet2!A1,TRUE,FALSE)

Then use the format painter for the whole sheet.
 
Upvote 0
How about just using a conditional format?

=IF(Sheet1!A1<>Sheet2!A1,TRUE,FALSE)

Then use the format painter for the whole sheet.

Well I have a group of over 25 users with abysmal Excel abilities.

So I have created a custom UI within the Excel interface itself that displays buttons.

They simply point and click. So the code runs for them.

Looking for a one button solution with automation rather than manual methods.

Thank you for the input though!
 
Upvote 0
Bump.. if anyone can help me out I'd really appreciate it.
 
Upvote 0
My last bump before letting this sink into the abyss.
 
Upvote 0
Hia
Is this what you're after?
Code:
Sub QC_Check()

If MsgBox("Highlight Discrepancies Between Sheet1 and Sheet2?", vbYesNo) = vbNo Then Exit Sub
    
'Check For Discrepancies and Highlight
' C is Cell Comparison
' Solve for X to identify discrepancies

    Dim x As Long
    x = 0
    Dim c As Range


    With Sheets(1).Cells
        .Columns.AutoFit
        With .Interior
            .Pattern = xlNone
           .TintAndShade = 0
           .PatternTintAndShade = 0
        End With
    End With
    
    With Sheets(2).Cells
        .Columns.AutoFit
        With .Interior
            .Pattern = xlNone
           .TintAndShade = 0
           .PatternTintAndShade = 0
        End With
    End With
    
    Sheets(1).Select


    For Each c In Sheets(1).UsedRange
        If c.Text <> Sheets(2).Range(c.Address).Text Then
            c.Interior.Color = vbYellow
            If Range("A" & c.Row & ":F" & c.Row).Interior.Color = vbYellow Then
                MsgBox "Row" & c.Row
                Exit For
            End If
            
            x = x + 1
        End If
    Next c


MsgBox "There Are " & x & " Discrepancies"

End Sub
 
Upvote 0

Forum statistics

Threads
1,217,413
Messages
6,136,474
Members
450,015
Latest member
excel_beta_345User

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