Need guidance on finding duplicate data in a multisheet workbook

gray_b

New Member
Joined
Apr 17, 2019
Messages
34
Office Version
  1. 365
Platform
  1. Windows
I have a 25 sheet workbook, that I need to highlight duplicates in only 1 column (the same column) in each sheet. Each sheet has another 15 columns of other data. The data is a 4 digit number. But maybe changing that to a string of text in the future.

I have tried using conditional formatting, but this is not reliable over multi sheets. It works in a limited way, but it does not pick up all duplicates.

I have tried 'record macro' in createing conditional formating, but it does not record anything. Was hoping on using the code, and inserting it into each worksheet.

I have scoured google, and I have tried numerous vba code snippets. But again nothing fits my requirements.

I need guidance on creating a suitable macro that uses "Private Sub Workbook_Open()"

Any advice and guidance please.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Or you can put in an auxiliary column the sum of counts, if greater than 0 then there is a duplicate. In your conditional format you can refer to the auxiliary column.

Formula in auxiliary column

=COUNTIF(nsheet2,B3)+COUNTIF(nsheet3,B3)+COUNTIF(nsheet4,B3)
 
Upvote 0

Really strange.

I copied the condition formatting over from your workbook, to my workbook and nothing works.

However in saving your workbook and coping my data over to your workbook, it works.

Must be a bug somewhere in my Excel 2019? or in the Excel template.

Anyhow.

It does not highlight duplicates that are in the 1st worksheet.
Or the duplicates in 2nd worksheet that occur in the 1st worksheet.
Or any duplicates between Worksheet 2 and Worksheet 3.

It only compares worksheet1 to worksheet2 and then 1 to 3


Anyhow good going, any further input to get me on the right track.
 
Upvote 0
Of course, it's just an example so you can take it as a reference and make all the references you need.

Any advice and guidance please.

You could try the following code in the open event, check all the values ​​in column B of all the sheets against column B of all the sheets.

Code:
Private Sub Workbook_Open()    Dim sh As Worksheet, sh2 As Worksheet, c As String, d As Range, b As Range
    c = "B"
    
    For Each sh In Sheets
        sh.Range(c & ":" & c).Interior.ColorIndex = xlNone
    Next
    '
    For Each sh In Sheets
        For Each d In sh.Range(c & "1", sh.Range(c & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeConstants, 23)
            If d.Interior.ColorIndex = xlNone Then
                For Each sh2 In Sheets
                    If sh2.Name <> sh.Name Then
                        Set b = sh2.Range(c & ":" & c).Find(d.Value, LookIn:=xlValues, lookat:=xlWhole)
                        If Not b Is Nothing Then
                            d.Interior.ColorIndex = 6
                            b.Interior.ColorIndex = 6
                        End If
                    End If
                Next
            End If
        Next
    Next
End Sub

Try and tell me.
 
Upvote 0
Of course, it's just an example so you can take it as a reference and make all the references you need.



You could try the following code in the open event, check all the values ​​in column B of all the sheets against column B of all the sheets.

Code:
Private Sub Workbook_Open()    Dim sh As Worksheet, sh2 As Worksheet, c As String, d As Range, b As Range
    c = "B"
    
    For Each sh In Sheets
        sh.Range(c & ":" & c).Interior.ColorIndex = xlNone
    Next
    '
    For Each sh In Sheets
        For Each d In sh.Range(c & "1", sh.Range(c & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeConstants, 23)
            If d.Interior.ColorIndex = xlNone Then
                For Each sh2 In Sheets
                    If sh2.Name <> sh.Name Then
                        Set b = sh2.Range(c & ":" & c).Find(d.Value, LookIn:=xlValues, lookat:=xlWhole)
                        If Not b Is Nothing Then
                            d.Interior.ColorIndex = 6
                            b.Interior.ColorIndex = 6
                        End If
                    End If
                Next
            End If
        Next
    Next
End Sub

Try and tell me.

That works spot on, first time I tried it. Now I will try and incorporate it into my actual workbook.
 
Upvote 0

Forum statistics

Threads
1,223,981
Messages
6,175,767
Members
452,668
Latest member
mrider123

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