Note: The other languages of the website are Google-translated. Back to English
Log in  \/ 
x
or
x
Register  \/ 
x

or

How to highlight duplicate values in different colors in Excel?

doc different colors duplicates 1

In Excel, we can easily highlight the duplicate values in a column with one color by using the Conditional Formatting, but, sometimes, we need to highlight the duplicate values in different colors to recognize the duplicates quickly and easily as following screenshot shown. How could you solve this task in Excel?

Highlight duplicate values in a column with different colors by using VBA code


arrow blue right bubble Highlight duplicate values in a column with different colors by using VBA code

In fact, there is no direct way for us to finish this job in Excel, but, the below VBA code may help you, please do as follows:

1. Select the column of values that you want to highlight duplicates with difference colors, then hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.

2. Click Insert > Module, and paste the following code in the Module Window.

VBA code: Highlight duplicate values in different colors:

Sub ColorCompanyDuplicates()
'Updateby Extendoffice
    Dim xRg As Range
    Dim xTxt As String
    Dim xCell As Range
    Dim xChar As String
    Dim xCellPre As Range
    Dim xCIndex As Long
    Dim xCol As Collection
    Dim I As Long
    On Error Resume Next
    If ActiveWindow.RangeSelection.Count > 1 Then
      xTxt = ActiveWindow.RangeSelection.AddressLocal
    Else
      xTxt = ActiveSheet.UsedRange.AddressLocal
    End If
    Set xRg = Application.InputBox("please select the data range:", "Kutools for Excel", xTxt, , , , , 8)
    If xRg Is Nothing Then Exit Sub
    xCIndex = 2
    Set xCol = New Collection
    For Each xCell In xRg
      On Error Resume Next
      xCol.Add xCell, xCell.Text
      If Err.Number = 457 Then
        xCIndex = xCIndex + 1
        Set xCellPre = xCol(xCell.Text)
        If xCellPre.Interior.ColorIndex = xlNone Then xCellPre.Interior.ColorIndex = xCIndex
        xCell.Interior.ColorIndex = xCellPre.Interior.ColorIndex
      ElseIf Err.Number = 9 Then
        MsgBox "Too many duplicate companies!", vbCritical, "Kutools for Excel"
        Exit Sub
      End If
      On Error GoTo 0
    Next
End Sub

3. And then press F5 key to run this code, and a prompt box will remind you to select the data range that you want to highlight the duplicate values, see screenshot:

doc different colors duplicates 2

4. Then click OK button, all the duplicate values have been highlighted in different colors, see screenshot:

doc different colors duplicates 1


The Best Office Productivity Tools

Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial. 60-day money back guarantee.
kte tab 201905

Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
officetab bottom
Say something here...
symbols left.
You are guest
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    skyyang · 3 months ago
    @Sadie737 Hi, Sadie,
    To ignore the empty cells, please apply the below code:
    Sub ColorCompanyDuplicates() 'Updateby Extendoffice Dim xRg As Range Dim xTxt As String Dim xCell As Range Dim xChar As String Dim xCellPre As Range Dim xCIndex As Long Dim xCol As Collection Dim I As Long On Error Resume Next If ActiveWindow.RangeSelection.Count > 1 Then xTxt = ActiveWindow.RangeSelection.AddressLocal Else xTxt = ActiveSheet.UsedRange.AddressLocal End If Set xRg = Application.InputBox("please select the data range:", "Kutools for Excel", xTxt, , , , , 8) If xRg Is Nothing Then Exit Sub xCIndex = 2 Set xCol = New Collection For Each xCell In xRg On Error Resume Next If xCell.Value <> "" Then xCol.Add xCell, xCell.Text If Err.Number = 457 Then xCIndex = xCIndex + 1 Set xCellPre = xCol(xCell.Text) If xCellPre.Interior.ColorIndex = xlNone Then xCellPre.Interior.ColorIndex = xCIndex xCell.Interior.ColorIndex = xCellPre.Interior.ColorIndex ElseIf Err.Number = 9 Then MsgBox "Too many duplicate companies!", vbCritical, "Kutools for Excel" Exit Sub End If On Error GoTo 0 End If Next End Sub
    Please try, hope it can help you!
  • To post as a guest, your comment is unpublished.
    Sadie737 · 3 months ago
    Hi, is there any way to have this code ignore empty cells? When I put in the code it highlighted all of the empty cells and I need them to be blank.
    Thank you!
  • To post as a guest, your comment is unpublished.
    sajith · 4 months ago
    @Sajith It's not working. something wrong?

  • To post as a guest, your comment is unpublished.
    Sajith · 4 months ago
    @skyyang Thanks a lot. Can I have a email or something?
  • To post as a guest, your comment is unpublished.
    skyyang · 4 months ago
    @sajith Hello, sajith,
    To highlight the duplicates with different font colors, please apply the below formula:
    Sub ColorCompanyDuplicates() 'Updateby Extendoffice Dim xRg As Range Dim xTxt As String Dim xCell As Range Dim xChar As String Dim xCellPre As Range Dim xCIndex As Long Dim xCol As Collection Dim I As Long On Error Resume Next If ActiveWindow.RangeSelection.Count > 1 Then xTxt = ActiveWindow.RangeSelection.AddressLocal Else xTxt = ActiveSheet.UsedRange.AddressLocal End If Set xRg = Application.InputBox("please select the data range:", "Kutools for Excel", xTxt, , , , , 8) If xRg Is Nothing Then Exit Sub xCIndex = 2 Set xCol = New Collection For Each xCell In xRg On Error Resume Next xCol.Add xCell, xCell.Text If Err.Number = 457 Then xCIndex = xCIndex + 1 Set xCellPre = xCol(xCell.Text) If xCellPre.Font.ThemeColor = xlNone Then xCellPre.Font.ThemeColor = xCIndex xCell.Font.ThemeColor = xCellPre.Font.ThemeColor ElseIf Err.Number = 9 Then MsgBox "Too many duplicate companies!", vbCritical, "Kutools for Excel" Exit Sub End If On Error GoTo 0 Next End Sub
    Please try, hope it can help you!
  • To post as a guest, your comment is unpublished.
    sajith · 4 months ago
    IS THERE ANY VBA CODE TO HIGHLIGHT DUPLICATES BY DIFFERENT FONT COLORS?


  • To post as a guest, your comment is unpublished.
    FannieM · 5 months ago
    Hello I need help highlighting cells only if they repeat consecutively with 2 cell colors. This is a sample of end result.

    95
    83
    68
    94
    97
    95.** Highlight with color 1
    95 ** Highlight with color 1
    95** Highlight with color 1
    78
    92
    65
    85
    79
    94
    83
    91
    68** Highlight with 2nd color
    68** Highlight with 2nd color
    68** Highlight with 2nd color
    80
    70
    83**Highlight with color 1
    83**Highlight with color 1
    94
    65
    83
    12
    65** Highlight with 2nd color
    65** Highlight with 2nd color
    65** Highlight with 2nd color


  • To post as a guest, your comment is unpublished.
    FannieM · 5 months ago
    Hello, I need help highlighting duplicate values only if they are found repeating consecutively as a group using only two colors. if they appear only once elsewhere do not highlight.

    can someone help me with a code please?
    This is the sample end result i'm looking for.
  • To post as a guest, your comment is unpublished.
    ganesh ugale · 6 months ago
    You are champion..!!!

  • To post as a guest, your comment is unpublished.
    MB · 9 months ago
    How to Highlight Duplicate rows In A table With Different Colors By Using VBA Code ?
  • To post as a guest, your comment is unpublished.
    MB · 9 months ago
    Highlight Duplicate rows In A table With Different Colors By Using VBA Code

  • To post as a guest, your comment is unpublished.
    nasa · 1 years ago
    @Thomas Thank you so much Thomas! You just saved me!
  • To post as a guest, your comment is unpublished.
    skyyang · 1 years ago
    @Pavithra Hello, Pavithra,
    This code works well in my worksheet, which Excel version do you use?
    Or you can send your worksheet to my email, I test it for you!
    Thank you!
  • To post as a guest, your comment is unpublished.
    Pavithra · 1 years ago
    this macro stops after every 100 rows. I ahve dtaa with more than 5000 rows. then What Should i do with the code.
  • To post as a guest, your comment is unpublished.
    luis · 1 years ago
    hola y si quisiera combinar todas las celdas repetidas con sus similares
    de forma automática?? hacerlas una sola
  • To post as a guest, your comment is unpublished.
    Kelli · 1 years ago
    Whenever I run this code it seems to work for a few seconds (I can see the various colors in the appropriate column...) but when I try to scroll down to see the entire sheet, everything freezes. Eventually I get an error message that Excel is not responding... Any suggestions? My guess is that my spreadsheet is too large? Or I have too many Duplicate Vales and it's throwing Excel for a loop?? i.e. Recent spreadsheet had 567 cells in the column I was attempting to format and there were around 267 duplicates... Too much? Not enough colors in the rainbow, possibly? ;)
  • To post as a guest, your comment is unpublished.
    Douglas · 1 years ago
    what is the limit of duplicate values for the code to work properly?
  • To post as a guest, your comment is unpublished.
    skyyang · 1 years ago
    @Peter Hi, Peter,
    Sorry, maybe there is no direct code for coloring the cells dynamically when entering new data.
    If others have any good ideas, please comment here.
    Thank you!
  • To post as a guest, your comment is unpublished.
    skyyang · 1 years ago
    @debbie Hello, debbie,
    The code works well in my worksheet, which Excel version do you use?
    Or you can insert your problem screenshot here.
  • To post as a guest, your comment is unpublished.
    Alex · 1 years ago
    @Edward Hello,

    Is there a way to make this only effect the highlighted column and not the entire row? Some of the bold red and blue colors are hard to look at all the way across the spreadsheet. Thanks
  • To post as a guest, your comment is unpublished.
    debbie · 1 years ago
    I'm a beginner (obviously), but I keep getting the following error "Compile Error: Invalid outside procedure." Any suggestions?
  • To post as a guest, your comment is unpublished.
    Peter · 1 years ago
    Hallo and thx for your work - know its long time ago but still great to use

    I use it in a large address list and filter out all double entry’s - help a lot

    Now my question - is it possible to run this macro in some kind of live error check - I mean - if someone enter a doable address it get colored directly when I press enter.


    Sub ColorCompanyDuplicates()
    'Updateby Extendoffice 20171222
    Dim xRg As Range
    Dim xTxt As String
    Dim xCell As Range
    Dim xChar As String
    Dim xCellPre As Range
    Dim xCIndex As Long
    Dim xCol As Collection
    Dim I As Long
    On Error Resume Next
    If ActiveWindow.RangeSelection.Count > 1 Then
    xTxt = ActiveWindow.RangeSelection.AddressLocal
    Else
    xTxt = ActiveSheet.UsedRange.AddressLocal
    End If
    Set xRg = Range("M10:P10010")
    If xRg Is Nothing Then Exit Sub
    xCIndex = 2
    Set xCol = New Collection
    For Each xCell In xRg
    On Error Resume Next
    If xCell.Value <> "" Then
    xCol.Add xCell, xCell.Text
    If Err.Number = 457 Then
    xCIndex = xCIndex + 1
    Set xCellPre = xCol(xCell.Text)
    If xCellPre.Interior.ColorIndex = xlNone Then xCellPre.Interior.Color = RGB(xRed, xGreen, xBlue)
    xCell.Interior.Color = xCellPre.Interior.Color
    ElseIf Err.Number = 9 Then
    MsgBox "Too many duplicate companies!", vbCritical, "Kutools for Excel"
    Exit Sub
    End If
    xRed = Application.WorksheetFunction.RandBetween(0, 255)
    xGreen = Application.WorksheetFunction.RandBetween(0, 255)
    xBlue = Application.WorksheetFunction.RandBetween(0, 255)
    On Error GoTo 0
    End If
    Next
    End Sub


    Thx for your help
  • To post as a guest, your comment is unpublished.
    alex · 1 years ago
    I have 1039 rows some have duplicate names but when I run the code it seems to only highlight 100 of the rows and in between it misses some. Is the problem not to many colors? or is it too much to process? (there might be like 500-800 names that repeat)
  • To post as a guest, your comment is unpublished.
    javier · 1 years ago
    @Thomas Woow man, thanks !!! exactly what I was looking for!
  • To post as a guest, your comment is unpublished.
    skyyang · 1 years ago
    @Thomas Dear, Thomas,
    Thanks a lot for your code, your are a warm-hearted man, the code may help for others!
    Thanks again!
  • To post as a guest, your comment is unpublished.
    skyyang · 1 years ago
    @AW Hi, AW,
    To highlight entire documnet based on the duplicate cell values, you can apply the following VBA code:

    Sub ColorCompanyDuplicates()
    Dim xRg As Range
    Dim xTxt As String
    Dim xCell As Range
    Dim xChar As String
    Dim xCellPre As Range
    Dim xCIndex As Long
    Dim xCol As Collection
    Dim I As Long
    On Error Resume Next
    If ActiveWindow.RangeSelection.Count > 1 Then
    xTxt = ActiveWindow.RangeSelection.AddressLocal
    Else
    xTxt = ActiveSheet.UsedRange.AddressLocal
    End If
    Set xRg = Application.InputBox("please select the data range:", "Kutools for Excel", xTxt, , , , , 8)
    If xRg Is Nothing Then Exit Sub
    xCIndex = 2
    Set xCol = New Collection
    For Each xCell In xRg
    On Error Resume Next
    xCol.Add xCell, xCell.Text
    If Err.Number = 457 Then
    xCIndex = xCIndex + 1
    Set xCellPre = xCol(xCell.Text)
    If xCellPre.Interior.ColorIndex = xlNone Then xCellPre.EntireRow.Interior.ColorIndex = xCIndex
    xCell.EntireRow.Interior.ColorIndex = xCellPre.EntireRow.Interior.ColorIndex
    ElseIf Err.Number = 9 Then
    MsgBox "Too many duplicate companies!", vbCritical, "Kutools for Excel"
    Exit Sub
    End If
    On Error GoTo 0
    Next
    End Sub

    Please try it, hope it can help you!
  • To post as a guest, your comment is unpublished.
    Thomas · 2 years ago
    Because you are limited to 56 Colours using the *.ColorIndex you should probably consider using RGB colours.

    I have modified the code (note there is no if-statement for duplicate coloruing)…

    Sub ColorCompanyDuplicates()
    'Updateby Extendoffice 20160704
    Dim xRg As Range
    Dim xTxt As String
    Dim xCell As Range
    Dim xChar As String
    Dim xCellPre As Range
    Dim xCIndex As Long
    Dim xCol As Collection
    Dim I As Long
    On Error Resume Next
    If ActiveWindow.RangeSelection.Count > 1 Then
    xTxt = ActiveWindow.RangeSelection.AddressLocal
    Else
    xTxt = ActiveSheet.UsedRange.AddressLocal
    End If
    Set xRg = Application.InputBox("please select the data range:", "Kutools for Excel", xTxt, , , , , 8)
    If xRg Is Nothing Then Exit Sub
    xCIndex = 2
    Set xCol = New Collection
    For Each xCell In xRg
    On Error Resume Next
    xCol.Add xCell, xCell.Text
    If Err.Number = 457 Then
    xCIndex = xCIndex + 1
    Set xCellPre = xCol(xCell.Text)
    If xCellPre.Interior.ColorIndex = xlNone Then xCellPre.Interior.Color = RGB(xRed, xGreen, xBlue)
    xCell.Interior.Color = xCellPre.Interior.Color
    ElseIf Err.Number = 9 Then
    MsgBox "Too many duplicate companies!", vbCritical, "Kutools for Excel"
    Exit Sub
    End If
    xRed = Application.WorksheetFunction.RandBetween(0, 255)
    xGreen = Application.WorksheetFunction.RandBetween(0, 255)
    xBlue = Application.WorksheetFunction.RandBetween(0, 255)
    On Error GoTo 0
    Next
    End Sub
  • To post as a guest, your comment is unpublished.
    AW · 2 years ago
    How can you make it color the entire document if there are many rows?
  • To post as a guest, your comment is unpublished.
    skyyang · 2 years ago
    @Miles Hi, Miles,
    The above VBA code can not support to choose the colors, it fills the cells with random background color.
    If you have other good ideas, please comment here.
    Thank you!
  • To post as a guest, your comment is unpublished.
    Miles · 2 years ago
    Thanks for posting this, it's been very helpful! Which lines in the VBA code designate which colors will be used? I was looking for hex color codes in there but nothing was popping out.
  • To post as a guest, your comment is unpublished.
    Bree · 2 years ago
    Nvm i got it to work.
  • To post as a guest, your comment is unpublished.
    Bree · 2 years ago
    I can't get it to work it keeps crashing my Excel.
  • To post as a guest, your comment is unpublished.
    Татьяна · 2 years ago
    Огромное СПАСИБО !!!!
  • To post as a guest, your comment is unpublished.
    Prashanth · 2 years ago
    Oh Damn, You saved my time,,I was taking help of my colleagues all these days and no one had idea about it. Thanks a Ton !!!
  • To post as a guest, your comment is unpublished.
    skyyang · 2 years ago
    @Carol Hello, Carol,
    Could you send your workbook to my email address, I may help you to find the problem.
    My email address is :skyyang@extendoffice.com
  • To post as a guest, your comment is unpublished.
    Carol · 2 years ago
    My spreadsheet also stopped coloring at 178 and I have over 400 lines. How do you fix this?
  • To post as a guest, your comment is unpublished.
    Ahmed · 2 years ago
    @skyyang Hello,
    my excel sheet has 11000 row of data.
    how can I extend it to highlight all the duplicate in that long column.

    it stopped at row 77.

    Thanks,

    AK
  • To post as a guest, your comment is unpublished.
    hidayat_wijaya · 2 years ago
    This is really great, but colouring stopped after row 76 (5 colours). How can I this be extended too?
  • To post as a guest, your comment is unpublished.
    bruceluo7701@gmail.com · 2 years ago
    @skyyang there is some mistake regarding the colorindex setting, xCindex will be more than 56 if there are 56 row data in your sheet, system will ignore the sentence :
    If xCellPre.Interior.ColorIndex = xlNone Then xCellPre.Interior.ColorIndex = xCIndex
    xCell.Interior.ColorIndex = xCellPre.Interior.ColorIndex
    I correct the program like below: \
    if Err.number=457 then
    if xCellPre.Text<>xCell.Text Then
    xCindex=xCindex+1
    endif
    set.....
  • To post as a guest, your comment is unpublished.
    skyyang · 2 years ago
    @Anri Hello, Anri,
    The above code works well in my worksheet, i test it in 300 hundred rows.
    Please try it again. Or you can send your workbook file to my email account.
    My email account is: skyyang@extendoffice.com
  • To post as a guest, your comment is unpublished.
    Wojciech Radwan · 2 years ago
    @Sarah Replace line: Set xRg = Application.InputBox("please select the data range:", "Kutools for Excel", xTxt, , , , , 8)
    to
    Set xRg = Range("A1:A100")

    or if you have table you can apply to whole table column:
    Set xRg = Range("Table1[[#All],[Column1]]")

    just replace Table1 to your own name and Column1 to any table header you wish to apply this macro.


    Regards
    Wojciech
  • To post as a guest, your comment is unpublished.
    Anri · 2 years ago
    This is really great, but colouring stopped after row 66 (9 colours). How can I this be extended?
  • To post as a guest, your comment is unpublished.
    skyyang · 2 years ago
    @Hossein Hello, Hossein,
    May be the following code can do you a favor, please try it.

    Sub ColorCompanyDuplicates()
    'Updateby Extendoffice
    Dim xRg, xRgRow As Range
    Dim xTxt, xStr As String
    Dim xCell, xCellPre As Range
    Dim xCIndex As Long
    Dim xCol As Collection
    Dim I As Long
    If ActiveWindow.RangeSelection.Count > 1 Then
    xTxt = ActiveWindow.RangeSelection.AddressLocal
    Else
    xTxt = ActiveSheet.UsedRange.AddressLocal
    End If
    Set xRg = Application.InputBox("please select the data range:", "Kutools for Excel", xTxt, , , , , 8)
    If xRg Is Nothing Then Exit Sub
    xCIndex = 2
    Set xCol = New Collection
    For I = 1 To xRg.Rows.Count
    On Error Resume Next
    Set xRgRow = xRg.Rows(I)
    For Each xCell In xRgRow.Columns
    xStr = xStr & xCell.Text
    Next
    xCol.Add xRgRow, xStr
    If Err.Number = 457 Then
    xCIndex = xCIndex + 1
    Set xCellPre = xCol(xStr)
    If xCellPre.Interior.ColorIndex = xlNone Then xCellPre.Interior.ColorIndex = xCIndex
    xRgRow.Interior.ColorIndex = xCellPre.Interior.ColorIndex
    ElseIf Err.Number = 9 Then
    MsgBox "Too many duplicate companies!", vbCritical, "Kutools for Excel"
    Exit Sub
    End If
    On Error GoTo 0
    xStr = ""
    Next
    End Sub
  • To post as a guest, your comment is unpublished.
    Hossein · 2 years ago
    @skyyang how can I highlight the range of rows?
  • To post as a guest, your comment is unpublished.
    Priya · 2 years ago
    I am new to VBA. Is there any way, that we need not run the macro over and over, it is automated to highlight even if new cells are copied into the column where macro is programmed?
  • To post as a guest, your comment is unpublished.
    skyyang · 2 years ago
    @Vasil Hello, Vasil,
    To highlight duplicate values in a range of cell, please try the following vba code:

    Sub ColorCompanyDuplicates()
    'Updateby Extendoffice
    Dim xRg, xRgRow As Range
    Dim xTxt, xStr As String
    Dim xCell, xCellPre As Range
    Dim xCIndex As Long
    Dim xCol As Collection
    Dim I As Long
    If ActiveWindow.RangeSelection.Count > 1 Then
    xTxt = ActiveWindow.RangeSelection.AddressLocal
    Else
    xTxt = ActiveSheet.UsedRange.AddressLocal
    End If
    Set xRg = Application.InputBox("please select the data range:", "Kutools for Excel", xTxt, , , , , 8)
    If xRg Is Nothing Then Exit Sub
    xCIndex = 2
    Set xCol = New Collection
    For I = 1 To xRg.Rows.Count
    On Error Resume Next
    Set xRgRow = xRg.Rows(I)
    For Each xCell In xRgRow.Columns
    xStr = xStr & xCell.Text
    Next
    xCol.Add xRgRow, xStr
    If Err.Number = 457 Then
    xCIndex = xCIndex + 1
    Set xCellPre = xCol(xStr)
    If xCellPre.Interior.ColorIndex = xlNone Then xCellPre.Interior.ColorIndex = xCIndex
    xRgRow.Interior.ColorIndex = xCellPre.Interior.ColorIndex
    ElseIf Err.Number = 9 Then
    MsgBox "Too many duplicate companies!", vbCritical, "Kutools for Excel"
    Exit Sub
    End If
    On Error GoTo 0
    xStr = ""
    Next
    End Sub

    Hope it can help you.
  • To post as a guest, your comment is unpublished.
    skyyang · 2 years ago
    @Bobo Hi, Bobo,
    To highlight entire row based on the duplicate cell values, you can apply the following VBA code:

    Sub ColorCompanyDuplicates()
    Dim xRg As Range
    Dim xTxt As String
    Dim xCell As Range
    Dim xChar As String
    Dim xCellPre As Range
    Dim xCIndex As Long
    Dim xCol As Collection
    Dim I As Long
    On Error Resume Next
    If ActiveWindow.RangeSelection.Count > 1 Then
    xTxt = ActiveWindow.RangeSelection.AddressLocal
    Else
    xTxt = ActiveSheet.UsedRange.AddressLocal
    End If
    Set xRg = Application.InputBox("please select the data range:", "Kutools for Excel", xTxt, , , , , 8)
    If xRg Is Nothing Then Exit Sub
    xCIndex = 2
    Set xCol = New Collection
    For Each xCell In xRg
    On Error Resume Next
    xCol.Add xCell, xCell.Text
    If Err.Number = 457 Then
    xCIndex = xCIndex + 1
    Set xCellPre = xCol(xCell.Text)
    If xCellPre.Interior.ColorIndex = xlNone Then xCellPre.EntireRow.Interior.ColorIndex = xCIndex
    xCell.EntireRow.Interior.ColorIndex = xCellPre.EntireRow.Interior.ColorIndex
    ElseIf Err.Number = 9 Then
    MsgBox "Too many duplicate companies!", vbCritical, "Kutools for Excel"
    Exit Sub
    End If
    On Error GoTo 0
    Next
    End Sub

    Please try it, hope it can help you!
  • To post as a guest, your comment is unpublished.
    eddvp · 2 years ago
    @bhaggi the same problem with me... color is too dark to read...
  • To post as a guest, your comment is unpublished.
    Vasil · 2 years ago
    Is there a way to change the script to work for (look at) table array instead of column? For example F2:BC117.
    Thank you!
  • To post as a guest, your comment is unpublished.
    John · 2 years ago
    @skyyang It seems to always use the same color palette though, is there a way to select the palette it uses? It's giving me some really dark colors through which the text is unreadable.