Code To Find Duplicates And Highlight

Dazzawm

Well-known Member
Joined
Jan 24, 2011
Messages
3,748
Office Version
  1. 365
Platform
  1. Windows
Is there a code or formula for when there is matching cells in column C that will then look in column AE and highlight any duplicate values please?
 
it ran for about an hour and crashed excel
Not really surprising, you should never use entire column references in an array formula. Especially when it;s use for CF which is highly volatile.
 
Upvote 0

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Not really surprising, you should never use entire column references in an array formula. Especially when it;s use for CF which is highly volatile.
Are you able to come up with a Macro please Fluff?
 
Upvote 0
I thought conditional formatting would be faster. I'll write the code.
One question, Is data on column C always in blocks?
 
Last edited by a moderator:
Upvote 0
I thought conditional formatting would be faster. I'll write the code.
One question, Is data on column C always in blocks?
Ye, a single row or blocks up to about a dozen, could be any amount really.
 
Upvote 0
This must do the trick. I can't guarantee the speed:
VBA Code:
Sub test()
  Dim d As Object, columnC As Variant, columnAE As Variant, i As Long, j As Long, counter As Long
  Set d = CreateObject("Scripting.Dictionary")
  With Application
  columnC = .Transpose(Intersect(UsedRange, Columns("C")))
  columnAE = .Transpose(Intersect(UsedRange, Columns("AE")))
  End With
  
  For i = 2 To UBound(columnC)
    If columnC(i) = columnC(i - 1) Then
      d.Add columnAE(i - 1), 1
      If d.Exists(columnAE(i)) Then
      counter = 1
        For j = i To UBound(columnC)
          If columnC(i - 1) = columnC(j) Then
            counter = counter + 1
          Else
            Exit For
          End If
        Next
        Cells(i - 1, 3).Resize(counter).Interior.Color = 65535
        d.RemoveAll
        i = j - 1
      End If
    Else
      d.RemoveAll
    End If
  Next
End Sub
 
Upvote 0
BTW, setting ScreenUpdate to false may speed up the process.
VBA Code:
Sub test()
  Dim d As Object, columnC As Variant, columnAE As Variant, i As Long, j As Long, counter As Long
  Set d = CreateObject("Scripting.Dictionary")
  With Application
  columnC = .Transpose(Intersect(UsedRange, Columns("C")))
  columnAE = .Transpose(Intersect(UsedRange, Columns("AE")))
  .ScreenUpdating = False
 
  For i = 2 To UBound(columnC)
    If columnC(i) = columnC(i - 1) Then
      d.Add columnAE(i - 1), 1
      If d.Exists(columnAE(i)) Then
      counter = 1
        For j = i To UBound(columnC)
          If columnC(i - 1) = columnC(j) Then
            counter = counter + 1
          Else
            Exit For
          End If
        Next
        Cells(i - 1, 3).Resize(counter).Interior.Color = 65535
        d.RemoveAll
        i = j - 1
      End If
    Else
      d.RemoveAll
    End If
  Next

  .ScreenUpdating = True
  End With
End Sub
 
Upvote 0
BTW, setting ScreenUpdate to false may speed up the process.
VBA Code:
Sub test()
  Dim d As Object, columnC As Variant, columnAE As Variant, i As Long, j As Long, counter As Long
  Set d = CreateObject("Scripting.Dictionary")
  With Application
  columnC = .Transpose(Intersect(UsedRange, Columns("C")))
  columnAE = .Transpose(Intersect(UsedRange, Columns("AE")))
  .ScreenUpdating = False
 
  For i = 2 To UBound(columnC)
    If columnC(i) = columnC(i - 1) Then
      d.Add columnAE(i - 1), 1
      If d.Exists(columnAE(i)) Then
      counter = 1
        For j = i To UBound(columnC)
          If columnC(i - 1) = columnC(j) Then
            counter = counter + 1
          Else
            Exit For
          End If
        Next
        Cells(i - 1, 3).Resize(counter).Interior.Color = 65535
        d.RemoveAll
        i = j - 1
      End If
    Else
      d.RemoveAll
    End If
  Next

  .ScreenUpdating = True
  End With
End Sub
Got an error on

columnC = .Transpose(Intersect(UsedRange, Columns("C")))
 
Upvote 0
I cant say that was very successful, it ran for about an hour and crashed excel. It was a big file to be fair. Is there a macro that will do the same?
About how many rows is your data in col C?
Another option to try:
VBA Code:
Sub Dazzawm_1()
'' section group looping
Dim i As Long, j As Long, n As Long
Dim c As Range, a
Dim t As Double
t = Timer - t
Range("C:C").Interior.Color = xlNone
n = Range("C" & Rows.Count).End(xlUp).Row

For i = 2 To n
    If Len(Cells(i, "C")) > 0 Then
        j = WorksheetFunction.CountIf(Range("C" & i & ":C" & n), Cells(i, "C")) 'case insensitive
'            Debug.Print Cells(i, "A").Resize(j).Address
            a = WorksheetFunction.Unique(Cells(i, "AE").Resize(j))
            If UBound(a) < j Then
                If c Is Nothing Then
                    Set c = Cells(i, "C").Resize(j)
                Else
                    Set c = Union(c, Cells(i, "C").Resize(j))
                End If
            End If
            i = i + j - 1
    End If
Next
c.Interior.Color = vbYellow
Debug.Print "It's done in:  " & Format(Timer - t, "0.00") & " seconds"
End Sub

Book1
BCDADAEAF
1
2Ga
3Gb
4Ja
5Kb
6Ma
7Ma
8Mb
9Sa
10Sb
11Sc
12Ua
13Ub
14Ua
15
Sheet1
 
Upvote 0
About how many rows is your data in col C?
Another option to try:
VBA Code:
Sub Dazzawm_1()
'' section group looping
Dim i As Long, j As Long, n As Long
Dim c As Range, a
Dim t As Double
t = Timer - t
Range("C:C").Interior.Color = xlNone
n = Range("C" & Rows.Count).End(xlUp).Row

For i = 2 To n
    If Len(Cells(i, "C")) > 0 Then
        j = WorksheetFunction.CountIf(Range("C" & i & ":C" & n), Cells(i, "C")) 'case insensitive
'            Debug.Print Cells(i, "A").Resize(j).Address
            a = WorksheetFunction.Unique(Cells(i, "AE").Resize(j))
            If UBound(a) < j Then
                If c Is Nothing Then
                    Set c = Cells(i, "C").Resize(j)
                Else
                    Set c = Union(c, Cells(i, "C").Resize(j))
                End If
            End If
            i = i + j - 1
    End If
Next
c.Interior.Color = vbYellow
Debug.Print "It's done in:  " & Format(Timer - t, "0.00") & " seconds"
End Sub

Book1
BCDADAEAF
1
2Ga
3Gb
4Ja
5Kb
6Ma
7Ma
8Mb
9Sa
10Sb
11Sc
12Ua
13Ub
14Ua
15
Sheet1
Could be anything up to about 150, 000 rows.
 
Upvote 0

Forum statistics

Threads
1,215,851
Messages
6,127,307
Members
449,374
Latest member
analystvar

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