Need help

Plukey

Board Regular
Joined
Apr 19, 2019
Messages
138
Office Version
  1. 2016
Platform
  1. Windows
I have code that High Lights Duplicates in a Workbook. Out of the 12 sheets only 7, I want to find dup's. All 7 are formatted as Table's and are identical. It also high lights the tab when one is found. It works perfect but I cant figure out how to exclude 4 of the sheets. Columns are A - T and it searches through B .


Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
 Dim ws As Worksheet, Dn As Range, Q As Variant
 With CreateObject("scripting.dictionary")
 .CompareMode = vbTextCompare
Application.ScreenUpdating = False
 For Each ws In Worksheets
    ws.Tab.ColorIndex = xlColorIndexNone '<<<
    ws.Range("B2:B106").Interior.ColorIndex = xlNone
        For Each Dn In ws.Range("B2:B106")
            If Dn.Value <> "" Then
                If Not .exists(Dn.Value) Then
                    .Add Dn.Value, Array(Dn, ws)
                Else
                    Q = .Item(Dn.Value)
                        Q(0).Interior.Color = vbRed
                        Dn.Interior.Color = vbRed
                        ws.Tab.Color = 225
                        Q(1).Tab.Color = 225
                    .Item(Dn.Value) = Q
                End If
            End If
        Next Dn
 Next ws
 
Application.ScreenUpdating = True '<<<
End With
End Sub
 
Last edited by a moderator:
@Plukey, you also need all instances of Sheet.Name changed to ws.Name.

The End If btw should be placed as below....

Code:
                Next Dn
           [COLOR="#FF0000"] End If[/COLOR]
        Next ws
 
Upvote 0

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Oh!!! That's it... Ive been working on this Workbook for a week! Dang thanks guys!!!!
 
Upvote 0
Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
 Dim ws As Worksheet, Dn As Range, Q As Variant
 With CreateObject("scripting.dictionary")
 .CompareMode = vbTextCompare
Application.ScreenUpdating = False
 For Each ws In Worksheets
If ws.Name <> "HOMEPAGE" And ws.Name <> "Other" And ws.Name <> "Closed PS" And ws.Name <> "Backlog to Research" And ws.Name <> "Pre-Scrap" Then
    ws.Tab.ColorIndex = xlColorIndexNone '<<<
    ws.Range("B2:B106").Interior.ColorIndex = xlNone
        For Each Dn In ws.Range("B2:B106")
            If Dn.Value <> "" Then
                If Not .exists(Dn.Value) Then
                    .Add Dn.Value, Array(Dn, ws)
                Else
                    Q = .Item(Dn.Value)
                        Q(0).Interior.Color = vbRed
                        Dn.Interior.Color = vbRed
                        ws.Tab.Color = 225
                        Q(1).Tab.Color = 225
                    .Item(Dn.Value) = Q
                    End If
                End If
            Next Dn
        End If
 Next ws
 
Application.ScreenUpdating = True '<<<
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,723
Messages
6,174,115
Members
452,545
Latest member
boybenqn

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