【问题标题】:Highlighting duplicates within and across sheets in excel在excel中突出显示工作表内和工作表之间的重复项
【发布时间】:2021-10-24 00:34:20
【问题描述】:

我正在尝试在 Excel 中突出显示工作表内和工作表之间的重复项。每张纸都设置相同,我只需要检查 C 列。我也想忽略空白单元格。我试着用谷歌搜索,但找不到我要找的东西。

我熟悉 Excel,我知道如何在 VBA 中输入内容,但这是我的知识范围。

【问题讨论】:

  • 查看条件格式
  • 谢谢。我做到了,但我不知道如何在整个工作簿中运行它。
  • 也许更详细地阐明您要做什么 - 以及文件/工作表的结构?

标签: excel vba duplicates


【解决方案1】:

试试这个:

Sub HiliteDupsAcrossSheets()

    Dim wb As Workbook, ws As Worksheet, c As Range, v
    Dim dict As Object
    
    Set dict = CreateObject("scripting.dictionary")
    
    Set wb = ActiveWorkbook 'for example
    
    For Each ws In wb.Worksheets
        'col C only
        For Each c In ws.Range("C1:C" & ws.Cells(Rows.Count, "C").End(xlUp).Row).Cells
            v = c.Value
            If Len(v) > 0 Then
                If dict.exists(v) Then
                    If Not dict(v) Is Nothing Then
                        dict(v).Interior.Color = vbRed 'color the first instance
                        Set dict(v) = Nothing          ' mark done
                    End If
                    c.Interior.Color = vbRed   'color cell `c`
                Else
                    Set dict(v) = c  'first time seeing this value: store location
                    c.Interior.ColorIndex = xlNone 'clear any previous coloring
                End If
            End If
        Next c
    Next ws

End Sub

【讨论】:

  • 谢谢你:)。这样可行。数据每天输入,是否会自动更新以突出显示新的重复项?
  • 否 - 您需要运行它来刷新颜色。您还需要清除之前运行的所有颜色,以防这些单元格不再重复。
  • 添加了一行以清除上一次运行的 hiliting。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-11-10
  • 2014-10-04
  • 1970-01-01
  • 2018-08-23
  • 2014-01-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多