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:

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
What are the Sheet Names to be excluded

Code:
If ws.Name <> "SheetToBeExcluded" and ws.Name <> "SecondSheetToBeExcluded" and ....... then
 
Upvote 0
If Sheet.Name <> "HOMEPAGE" And Sheet.Name <> "Other" And Sheet.Name <> "Closed PS" And Sheet.Name <> "Backlog to Research" And Sheet.Name <> "Pre-Scrap" Then

This what I've tried an I get Compile Error Next without for
 
Upvote 0
Show us your updated code with the amendments you made that is giving you this error. Cannot fix what I cannot see.
 
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 Sheet.Name <> "HOMEPAGE" And Sheet.Name <> "Other" And Sheet.Name <> "Closed PS" And Sheet.Name <> "Backlog to Research" And Sheet.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
 Next ws
 
Application.ScreenUpdating = True '<<<
End With
End Sub


F8P8AokgoqIO374QAAAAASUVORK5CYII=
 
Upvote 0
I have know idea what just happen...Im home from work and I tried to type the error code.
 
Upvote 0
You inserted this line of code

Code:
If Sheet.Name <> "HOMEPAGE" And Sheet.Name <> "Other" And Sheet.Name <> "Closed PS" And Sheet.Name <> "Backlog to Research" And Sheet.Name <> "Pre-Scrap" Then
but there is no End If statement for this

For each IF statement there needs to be an end if statement unless the Then statement is on the same line.
 
Upvote 0
I added an End If still getting Error on ...End if without Block if????
 
Upvote 0

Forum statistics

Threads
1,213,543
Messages
6,114,243
Members
448,555
Latest member
RobertJones1986

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