[excel2007] highlight duplicates.

montecarlo2012

Well-known Member
Joined
Jan 26, 2011
Messages
986
Office Version
  1. 2010
Platform
  1. Windows
If any cell on Sheet1 B2:F2 match any cell on sheet 2 B2:F2 then highlight the duplicates on sheet 2
If any cell on sheet1 B3:F3 match any cell on sheet 2 B3:F3 then highlight the duplicates on sheet 2
If any cell on sheet1 B4:F4 match any cell on sheet 2 B4:F4 then highlight the duplicates on sheet 2
If any cell on Sheet1 B5:F5 match any cell on sheet 2 B5:F5 then highlight the duplicates on sheet 2
If any cell on sheet1 B6:F6 match any cell on sheet 2 B6:F6 then highlight the duplicates on sheet 2
If any cell on sheet1 B7:F7 match any cell on sheet 2 B7:F7 then highlight the duplicates on sheet 2

And do this all the way down to the last row.
any help, please.
thanks for reading this.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Hi
Try
VBA Code:
Sub test()
    For i = 2 To Sheets("sheet2").Cells(Rows.Count, 2).End(xlUp).Row + 1
        With Sheets("sheet2")
            For ii = 1 To 5
                a = Application.Transpose(.Cells(i, 2).Resize(, 5))
                b = Application.Transpose(Sheets("sheet1").Cells(i, 2).Resize(, 5))
                x = Application.Match(b(ii, 1), a, 0)
                If IsNumeric(x) Then
                    .Cells(i, x + 1).Interior.Color = vbRed
                End If
            Next
        End With
    Next
End Sub
 
Upvote 0
Try:
VBA Code:
Sub CompareData()
    Application.ScreenUpdating = False
    Dim i As Long, r As Long, c As Long, sh1 As Worksheet, sh2 As Worksheet
    Dim v1 As Variant, v2 As Variant, val As String
    Set sh1 = Sheets("Sheet1")
    Set sh2 = Sheets("Sheet2")
    v1 = sh1.Range("B2", sh1.Range("B" & Rows.Count).End(xlUp)).Resize(, 5).Value
    v2 = sh2.Range("B2", sh2.Range("B" & Rows.Count).End(xlUp)).Resize(, 5).Value
    For i = LBound(v2) To UBound(v2)
        val = v2(i, 1) & "|" & v2(i, 2) & "|" & v2(i, 3) & "|" & v2(i, 4) & "|" & v2(i, 5)
        For r = LBound(v1) To UBound(v1)
            For c = LBound(v1, 2) To UBound(v1, 2)
                If InStr(1, val, v1(r, c)) > 0 Then
                    sh2.Cells(r + 1, c + 1).Interior.ColorIndex = 3
                End If
            Next c
        Next r
    Next i
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Do you need to do this with VBA, I believe conditional formatting was available in Excel 2007.
Try this conditional formatting rule on the cells in Sheet2, starting in cell B2 and highlight all your cells in the range:

Excel Formula:
=ISNUMBER(MATCH(B2,Sheet1!$B2:$F2,0))


Sheet 1:
Book1
ABCDEFG
1
2LOGMHMXRNBPLCLY
3UJCOZZKHBYWNIPX
4ZTOJHJJQQAMQUKS
5ZJSIWRBWZDIOPNS
6RPFXQNGFRXZCALH
7NQBPEGLCIAEEDMK
8
Sheet1



Sheet2:
Book1
ABCDEFG
1
2QGCBPLCLYBLCRCN
3TVNTEMDARNVVDIX
4LYQJMQQURMUDGOZ
5VGPCXHDJWLBOZJS
6QTTUJTMNKYNMPHY
7ITJCXWBINFXZPOB
8
Sheet2
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B2:F7Expression=ISNUMBER(MATCH(B2,Sheet1!$B2:$F2,0))textNO
 
Upvote 0
didn't work.
But It does work in here
And you did not mentioned any error message
Any way would you please try this
VBA Code:
Sub test()
Dim i&, ii&
Dim a, b, x
    For i = 2 To Sheets("sheet2").Cells(Rows.Count, 2).End(xlUp).Row + 1
        With Sheets("sheet2")
            For ii = 1 To 5
                a = Application.Transpose(.Cells(i, 2).Resize(, 5))
                b = Application.Transpose(Sheets("sheet1").Cells(i, 2).Resize(, 5))
                x = Application.Match(b(ii, 1), a, 0)
                If IsNumeric(x) Then
                    .Cells(i, x + 1).Interior.Color = vbRed
                End If
            Next
        End With
    Next
End Sub
 
Upvote 0
I figure out.
VBA Code:
Sub LToL()
    ' HIGHLIGHT THE MATCHES
    Dim rng As Range, fnd As Range
    Dim lastRow As Long
    Dim startingRow As Long

    ' Find the last row in column B on "Sheet1"
    lastRow = Sheets("Sheet1").Cells(Sheets("Sheet1").Rows.Count, "B").End(xlUp).Row

    For startingRow = 2 To lastRow ' Loop from row 2 to the last row on "Sheet1"
        For Each rng In Sheets("Sheet1").Range("B" & startingRow & ":F" & startingRow) ' READ columns B to F on "Sheet2"
            ' Search for the value in columns B to F on "Sheet2"
            Set fnd = Sheets("Sheet2").Range("B" & startingRow + 1 & ":F" & startingRow + 1).Find(rng.Value, LookIn:=xlValues, lookat:=xlWhole)  ' HIGHLIGHT
            If Not fnd Is Nothing Then
                fnd.Interior.ColorIndex = 6 ' Change color to yellow
            End If
        Next rng
    Next startingRow
End Sub
thanks
Awoohaw, Mohadin and Mumps for your time
I work out on it.
 
Upvote 0

Forum statistics

Threads
1,224,734
Messages
6,180,631
Members
452,991
Latest member
JM_000888

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