提示:其它语言是由 Google 机器翻译的。 你可以访问 English 版本。
登录
x
or
x
x
马上登记
x

or

如何在Excel中突出显示不同颜色的重复值?

doc不同的颜色重复1

在Excel中,我们可以用一种颜色轻松地突出显示一列中的重复值 条件格式但是,有时候,我们需要突出显示不同颜色的重复值,以便快速轻松地识别重复项,如下面的截图所示。 你怎么能在Excel中解决这个任务?

使用VBA代码突出显示具有不同颜色的列中的重复值


箭头蓝色右泡 使用VBA代码突出显示具有不同颜色的列中的重复值


事实上,我们没有直接的方式来完成这项工作在Excel中,但是,下面的VBA代码可以帮助你,请做如下:

1。 选择要用不同颜色突出显示重复项的值列,然后按住 ALT + F11 键打开 Microsoft Visual Basic for Applications 窗口。

2. 点击 插页 > 模块,并将以下代码粘贴到 模块 窗口。

VBA代码:突出显示不同颜色的重复值:

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.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。 然后按 F5 键来运行这个代码,并且一个提示框会提醒你选择你想要突出显示重复值的数据范围,看截图:

doc不同的颜色重复2

4。 然后点击 OK 按钮,所有重复的值都以不同的颜色突出显示,请参见截图:

doc不同的颜色重复1


Kutools for Excel - 最佳办公生产力工具提高80%的生产力

  • 重用: 快速插入 复杂的公式,图表 以及你以前用过的任何东西; 加密单元格 密码; 创建邮件列表 并发送电子邮件...
  • 超级方程式酒吧 (轻松编辑多行文字和公式); 阅读布局 (轻松读取和编辑大量单元格); 粘贴到过滤范围...
  • 合并单元格/行/列 不丢失数据; 分裂细胞含量; 组合重复的行/列...防止重复的细胞; 比较范围...
  • 选择复制或唯一 行; 选择空行 (所有细胞都是空的); 超级查找和模糊查找 在许多工作簿中; 随机选择......
  • 精确复制 多个单元格而不更改公式参考; 自动创建参考 多张表; 插入项目符号,复选框等等......
  • 提取文本,添加文本,按位置删除, 删除空间; 创建和打印分页小计; 在单元格内容和注释之间转换...
  • 超级过滤器 (将过滤方案保存并应用到其他工作表); 高级排序 按月/周/日,频率等; 特殊过滤器 用粗体,斜体......
  • 结合工作簿和工作表; 根据键列合并表; 将数据拆分为多个表格; 批量转换xls,xlsx和PDF...
  • 超过300强大的功能。 支持Office / Excel 2007-2019和365。 支持所有语言。 在您的企业或组织中轻松部署。 全功能60天免费试用。
kte tab 201905

Office选项卡为Office提供选项卡式界面,使您的工作更轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,Publisher,Access,Visio和Project。
  • 在同一窗口的新选项卡中打开并创建多个文档,而不是在新窗口中。
  • 通过50%提高您的工作效率,每天为您减少数百次鼠标点击!
官方底部
Say something here...
symbols left.
You are guest ( Sign Up? )
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.
    Douglas · 1 months ago
    what is the limit of duplicate values for the code to work properly?
  • To post as a guest, your comment is unpublished.
    debbie · 1 months 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.
      skyyang · 1 months ago
      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.
    Peter · 2 months 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.
      skyyang · 1 months ago
      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.
    alex · 2 months 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.
    Thomas · 4 months 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.
      javier · 3 months ago
      Woow man, thanks !!! exactly what I was looking for!
    • To post as a guest, your comment is unpublished.
      skyyang · 3 months ago
      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.
    AW · 6 months 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 · 3 months ago
      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.
    Miles · 7 months 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.
      skyyang · 6 months ago
      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.
    Bree · 7 months ago
    Nvm i got it to work.
  • To post as a guest, your comment is unpublished.
    Bree · 7 months ago
    I can't get it to work it keeps crashing my Excel.
  • To post as a guest, your comment is unpublished.
    Татьяна · 10 months ago
    Огромное СПАСИБО !!!!
  • To post as a guest, your comment is unpublished.
    Prashanth · 10 months 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.
    Carol · 11 months 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.
      skyyang · 11 months ago
      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.
    hidayat_wijaya · 1 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.
    Anri · 1 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 · 1 years ago
      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.
        Ahmed · 11 months ago
        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.
        Bruce luo · 1 years ago
        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.
    Priya · 1 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.
    Vasil · 1 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.
      skyyang · 1 years ago
      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.
    Bobo · 1 years ago
    Is there a way to highlight the entire row instead of 1 column?
    • To post as a guest, your comment is unpublished.
      skyyang · 1 years ago
      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.
        Hossein · 1 years ago
        how can I highlight the range of rows?
        • To post as a guest, your comment is unpublished.
          skyyang · 1 years ago
          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.
    selim · 1 years ago
    What If I just want to fill with only two colors, let's say yellow and red, repeatedly. To be clear, on the example in this page, 'Rachel' is yellow, Rose is red and again Sussies are yellow, Tedi is red.
    • To post as a guest, your comment is unpublished.
      skyyang · 1 years ago
      Hello, selim,
      The following code may solve your problem, please try.

      Sub ColorCompanyDuplicates()
      'Updateby Extendoffice 20170504
      Dim xRg As Range
      Dim xTxt As String
      Dim xCell As Range
      Dim xChar As String
      Dim xCellPre As Range
      Dim xRgTemp 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 = 3
      Set xCol = New Collection
      For Each xCell In xRg
      On Error Resume Next
      xCol.Add xCell, xCell.Text
      If Err.Number = 457 Then
      Set xCellPre = xCol(xCell.Text)
      xCell.Interior.ColorIndex = xCellPre.Interior.ColorIndex
      ElseIf Err.Number = 9 Then
      MsgBox "Too many duplicate companies!", vbCritical, "Kutools for Excel"
      Exit Sub
      Else
      xCell.Interior.ColorIndex = xCIndex
      Set xRgTemp = xCell
      xCIndex = IIf(xRgTemp.Interior.ColorIndex = 3, 4, 3)
      End If
      On Error GoTo 0
      Next
      End Sub

      Hope it can help you!
      • To post as a guest, your comment is unpublished.
        selim · 1 years ago
        This is what I exactly want it. Thank you much, skyyang.
  • To post as a guest, your comment is unpublished.
    Asking Man · 1 years ago
    Hello, I have Excel 2016, alt+F11 does work anymore to bring up Microsoft VB? is Microsoft visual basic free software? Thank you.
    • To post as a guest, your comment is unpublished.
      skyyang · 1 years ago
      Hi,
      If you can not activate the Microsoft VB window by holding down Alt + F11 keys, you can click Developer > Visual Basic to open it.

      Please try it, thank you!
  • To post as a guest, your comment is unpublished.
    shahinshah · 1 years ago
    Sir,
    How to differentiate different colors given in the data on the basis of frequency?
    In very large data same color has been given repeatedly without considering their frequency.
    • To post as a guest, your comment is unpublished.
      skyyang · 1 years ago
      Sorry, can you give more detailed information,you can attach a screenshot here.
      Thank you!
  • To post as a guest, your comment is unpublished.
    gopi · 1 years ago
    without empty to change a colour how ????????????????????
    • To post as a guest, your comment is unpublished.
      skyyang · 1 years ago
      Hello, gopi,
      To avoid the blank cells, please apply the following VBA code:
      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 = 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

      Hope it can help you, thank you!
  • To post as a guest, your comment is unpublished.
    bhaggi · 1 years ago
    how to change colour ?
    • To post as a guest, your comment is unpublished.
      Edmund Pelingon · 1 years ago
      the same problem with me... color is too dark to read...
    • To post as a guest, your comment is unpublished.
      skyyang · 1 years ago
      Hi,
      The code only can help you add the different color randomly, it can't change the color.
      Thank you!
      • To post as a guest, your comment is unpublished.
        John · 1 years ago
        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.
  • To post as a guest, your comment is unpublished.
    SHRIKANT NAYAK · 2 years ago
    I am really happy as I got what I was needed. Thanks
  • To post as a guest, your comment is unpublished.
    Sarah · 2 years ago
    This is great and EXACTLY what I was looking for! I'm incorporating this code into some existing code - I've written my code to select the cells that I want to color, and then I call the code to do the coloring. The only thing I can't figure out is how to bypass the msgBox that pops up and I have to click OK. I'm a novice at VBA and can't quite figure out how to alter this code.... Any suggestions, please! :)
    • To post as a guest, your comment is unpublished.
      Wojciech Radwan · 1 years ago
      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.
    Jason · 2 years ago
    I tried running this several times and every time I click "ok" it just sends me back to the modules screen. I'm using Excel 2010.
  • To post as a guest, your comment is unpublished.
    Josh · 2 years ago
    I had the same problem, the problem is the color index only goes to 56, so once it passes that it no longer colors the cells. To fix that, I replaced the line "xCIndex = xCIndex + 1" with the following:

    If xCIndex > 55 Then
    xCIndex = 3
    Else
    xCIndex = xCIndex + 1
    End If

    It will start reusing colors eventually, but that wasn't an issue for me.
    • To post as a guest, your comment is unpublished.
      Golzar · 1 years ago
      Thank you so much Josh, it works!
    • To post as a guest, your comment is unpublished.
      FRANK · 2 years ago
      The replace with

      If xCIndex > 55 Then
      xCIndex = 3
      Else
      xCIndex = xCIndex + 1
      End If



      Did not work. Trying to get this to work on 14000 lines, approx 6000 duplicates
      • To post as a guest, your comment is unpublished.
        Golzar · 1 years ago
        It worked for me, I indented the second and fourth lines. See below. Josh's code is bolded.

        If Err.Number = 457 Then
        If xCIndex > 55 Then
        xCIndex = 3
        Else
        xCIndex = xCIndex + 1
        End If
        Set xCellPre = xCol(xCell.Text)
  • To post as a guest, your comment is unpublished.
    ES · 2 years ago
    Same problem. Anyone figure this out?
  • To post as a guest, your comment is unpublished.
    Golzar · 2 years ago
    This has been a life saver for me, thank you so much for sharing!

    When I run it on about 2000 cells with values, it only highlights some of the duplicates. Is there a way to fix that? I wonder if it runs out of colors or there is something else.
    • To post as a guest, your comment is unpublished.
      yp · 2 years ago
      same problem i am trying with couple of hundred cells and very quickly it colors in same colors.
      is there a fix for this?
      thanks
  • To post as a guest, your comment is unpublished.
    Swapnil · 2 years ago
    i want to check the duplicates for 5000 cells which i am not able to do. i can highlight duplicates upto 70 to 80 cells
  • To post as a guest, your comment is unpublished.
    Patrick A. · 2 years ago
    This is just what I needed, thank you.

    Sometimes when I run this code Excel just freezes, I am using Office 2016 / Windows 10 any idea why?
    • To post as a guest, your comment is unpublished.
      Alan · 2 years ago
      Patrick, only highlight the cells you want. Don't highlight the entire column which will include all the thousands of blank cells
  • To post as a guest, your comment is unpublished.
    Edward · 2 years ago
    It worked for me on a list of part numbers.
    • To post as a guest, your comment is unpublished.
      Alex · 1 months ago
      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