Results 1 to 5 of 5

Help with Duplication formula please!

Threaded View

  1. #1
    Registered User
    Join Date
    08-30-2012
    Location
    Brisbane
    MS-Off Ver
    Excel 2007
    Posts
    14

    Help with Duplication formula please!

    Hi,

    I have this macro that does what I want it too.

    Sub findDuplicates()
     ' code to find duplicates in 2 different worksheets
    Dim rng1, rng2, cell1, cell2 As Range
    
    ' 4 ranges have been defined
    Set rng1 = Worksheets("Sheet1").Range("A:A")   'rng1 defines the existing data in column A and worksheet1
    Set rng2 = Worksheets("Sheet2").Range("C:C")   'rng2 defines the imported data in column C and worksheet2
     
    For Each cell1 In rng1
        If IsEmpty(cell1.Value) Then Exit For
        'check for empty rows. If true then exit the program
        For Each cell2 In rng2
            If IsEmpty(cell2.Value) Then Exit For
            If cell1.Value = cell2.Value Then
                'compare data in cell1 and cell2 and then format if they have equal values.
                cell1.Font.Bold = True
                cell1.Font.ColorIndex = 2
                cell1.Interior.ColorIndex = 3
                cell1.Interior.Pattern = xlSolid
                cell2.Font.Bold = True
                cell2.Font.ColorIndex = 2
                cell2.Interior.ColorIndex = 3
                cell2.Interior.Pattern = xlSolid
            End If
            'run the looping process
         Next cell2
     Next cell1
     
    End Sub
    Except I would like it to go through all worksheets, at the moment I change the Sheet2 part of the macro in this part to the name of the other worksheet: - "Set rng2 = Worksheets("Sheet2").Range("C:C")"

    Can anyone please tell me how I can change this to cycle through all Worksheets in the Book without me manually having to name each sheet and have it perform the same function? I have attached a sample worksheet with the macro, as you can see it only does Sheet A, I want it to do both Sheet A AND Sheet B if possible?

    Thanks!

    Sample Data.xlsm
    Last edited by JBeaucaire; 08-31-2012 at 12:16 AM. Reason: Added code tags, corrected title as per forum rules. PLEASE read the Forum Rules(link above) and follow them.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1