Need help

Plukey

Board Regular
Joined
Apr 19, 2019
Messages
61
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

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

alansidman

Well-known Member
Joined
Feb 26, 2007
Messages
6,184
Office Version
  1. 365
Platform
  1. Windows
What are the Sheet Names to be excluded

Code:
If ws.Name <> "SheetToBeExcluded" and ws.Name <> "SecondSheetToBeExcluded" and ....... then
 

Plukey

Board Regular
Joined
Apr 19, 2019
Messages
61
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
 

alansidman

Well-known Member
Joined
Feb 26, 2007
Messages
6,184
Office Version
  1. 365
Platform
  1. Windows
Probably missing an End if statement.
 

alansidman

Well-known Member
Joined
Feb 26, 2007
Messages
6,184
Office Version
  1. 365
Platform
  1. Windows
Show us your updated code with the amendments you made that is giving you this error. Cannot fix what I cannot see.
 

Plukey

Board Regular
Joined
Apr 19, 2019
Messages
61

ADVERTISEMENT

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=
 

Plukey

Board Regular
Joined
Apr 19, 2019
Messages
61
I have know idea what just happen...Im home from work and I tried to type the error code.
 

alansidman

Well-known Member
Joined
Feb 26, 2007
Messages
6,184
Office Version
  1. 365
Platform
  1. Windows
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.
 

Plukey

Board Regular
Joined
Apr 19, 2019
Messages
61
I added an End If still getting Error on ...End if without Block if????
 

Watch MrExcel Video

Forum statistics

Threads
1,129,467
Messages
5,636,446
Members
416,919
Latest member
twc2c

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
Top