Highlight Duplicate Values
Automatically highlight duplicate values in a range with conditional formatting
          
          384 views
        
          
            
            Featured
          
      Perfect For:
- Data validation
- Quality control
- Duplicate detection
        
        
        
        VBA Code
    
      
    Sub HighlightDuplicates()
    Dim dataRange As Range
    Dim cell As Range
    Dim duplicateFormat As FormatCondition
    ' Select the data range
    Set dataRange = Application.InputBox("Select range to check for duplicates:", Type:=8)
    If dataRange Is Nothing Then Exit Sub
    ' Clear existing conditional formatting
    dataRange.FormatConditions.Delete
    ' Add conditional formatting for duplicates
    Set duplicateFormat = dataRange.FormatConditions.AddUniqueValues
    duplicateFormat.DupeUnique = xlDuplicate
    duplicateFormat.Interior.Color = RGB(255, 199, 206)  ' Light red background
    duplicateFormat.Font.Color = RGB(156, 0, 6)         ' Dark red text
    MsgBox "Duplicate values highlighted successfully!"
End SubRelated Topics
            
              duplicates
            
            
              highlighting
            
            
              validation
            
            
              formatting
            
        
      Need Custom VBA Solutions?
Our AI-powered VBA generator can create custom code tailored to your specific requirements in seconds.
Generate Custom VBA Code