在excel中区分重复的值

我需要所有重复的具有相同的列颜色的特定值。这将帮助我find有多less重复的特定值,相应的列值等。请find示例Excel 。 如果我做条件格式化,突出显示重复,这将给所有重复相同的颜色,不pipe值。这不会解决的目的。 如果有的话,还build议用其他方法来区分excel中的重复值。

有没有办法做你想要的条件格式,但我认为下面的macros将做你想要的。 它build立一个唯一值的字典,并为每个颜色分配一个随机的颜色,然后匹配和重复使用任何重复项。

' Base function that can be used for different columns. Sub colorDistinctInColumn(ByVal columnLetter As String) Dim lastRow As Integer Dim i As Integer Dim dict Dim currentCell As Range Dim columnNumber As Integer ' Create a dictionary to hold the value/colour pairs Set dict = CreateObject("Scripting.Dictionary") ' Find the last-used cell in the column of interest lastRow = ActiveSheet.Columns(columnLetter).Cells.Find( _ "*", _ SearchOrder:=xlByRows, _ LookIn:=xlValues, _ SearchDirection:=xlPrevious).Row ' Pick columnNumber using the given column letter columnNumber = ActiveSheet.Columns(columnLetter).Column ' Loop through all of the cells For i = 1 To lastRow Set currentCell = ActiveSheet.Cells(i, columnNumber) ' See if we've already come across the current value If Not dict.exists(currentCell.Value) Then ' This value has not been encountered yet, ' so store it and assign a random colour dict.Add currentCell.Value, RGB(Rnd * 255, Rnd * 255, Rnd * 255) End If ' Set the colour of the current cell to whichever colour ' has been stored for the current cell's value currentCell.Interior.Color = dict(currentCell.Value) Next i Set dict = Nothing End Sub ' Actual Macro that will run in Excel Sub colorDistinctInColumnA() Call colorDistinctInColumn("A") End Sub