VBA Highlight Duplicates in a Column

Neveidas

New Member
Joined
Oct 6, 2021
Messages
44
Office Version
  1. 365
Platform
  1. Windows
Hello, as the thread title says it all, I am trying to create a VBA code to highlight duplicates in a single column, was thinking of adding on a delete duplicate code too but I'm afraid of deleting the wrong duplicate thus I am highlighting them first, below is the code that I am using currently, but when I delete the duplicates, the cells stay coloured. So is there a better way of having them highlighted so that when the duplicates are deleted, the cells won't be highlighted anymore? Thank you in advance for the help!

VBA Code:
Private Sub DupeClean()
Application.ScreenUpdating = False

    Dim r As Range, rr As Range
    Dim Main As Worksheet
    Dim i As Long



    Set Main = ThisWorkbook.Sheets("Import")

    i = Main.Range("D" & Rows.Count).End(xlUp).Row
    Set rr = Main.Range("D2:D" & i)


    For Each r In rr
        If WorksheetFunction.CountIf(rr, r.Value) > 1 Then _
        r.Interior.ColorIndex = 3
    Next

Application.ScreenUpdating = True

End Sub
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
You can use Conditional Formatting for that, it's on the Home Tab.
Click on Conditional Formatting, Highlight Cells Rules, Duplicate Values
 
Upvote 0
Solution
You can use Conditional Formatting for that, it's on the Home Tab.
Click on Conditional Formatting, Highlight Cells Rules, Duplicate Values
hello, yes I was using that before but because it is like a daily routine and there are multiple sets to go through, so I figured it might be better if I can do it with a click of a button
 
Upvote 0
hello, yes I was using that before but because it is like a daily routine and there are multiple sets to go through, so I figured it might be better if I can do it with a click of a button
Probably you just put the line to clear all (reset) colored interior before marking duplicate. So, after deleting the row, just run the macro again just like verification.
 
Upvote 0
Probably you just put the line to clear all (reset) colored interior before marking duplicate. So, after deleting the row, just run the macro again just like verification.
hmmm, because the Highlighting of Duplicate is actually a call function, so if I were to run it for checking again, I would have to run the whole chunk again. The excel workbook is more or less a template, so would it be a better idea to have done what Fluff have mentioned? so that when others are using the template, it would have already check for duplicates once there are duplicates?
 
Upvote 0
You could record a macro applying the conditional format, so that it can be done on the click of button.
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,950
Messages
6,122,436
Members
449,083
Latest member
Ava19

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