识别所有已被条件格式化的单元格

Identify all cells that have been conditionally formatted

我正在尝试删除重复值 除了第一个

我的解决方案是有条件地格式化所有重复项,然后反向工作,清除格式化单元格的内容。这意味着第一个将在删除所有重复项后停止格式化。

我一直在尝试的:

For i = LaC To 5 Step -1
LR = ws.Cells(Rows.Count, LaC).End(xlUp).Row
    For j = 2 To LR
    cond = (ws.Cells(j, i).DisplayFormat.Interior.ColourIndex.Value)
        If cond = 22 Then
            ws.Cells(j, i).ClearContents
        End If
    Next
Next

基本上,如果我立即尝试 ws.Cells(j, i).DisplayFormat.Interior.ColourIndex window,它 returns 22。

但是,如果我尝试此代码,我会收到错误消息:

Object doesn't support this property or method (Error 438)

如有任何帮助,我们将不胜感激。

如果不需要使用VBA,您可以通过“数据”→“数据工具”→“删除重复项”在GUI中删除重复项。或者,在当前版本的 Excel O365 中,您可以像这样使用 UNIQUE-函数

UNIQUE(A:A)

假设您的源数据在行 A 中。这将跟上不断变化的数据。

更仔细地检查这一行:

cond = (ws.Cells(j, i).DisplayFormat.Interior.ColourIndex.Value)

ColorIndex 是 属性,而不是 Object。因此,ColorIndex.Value 将 return 出错。请注意,在即时 Window 中测试时,您 没有 包含 .Value,它按预期工作:

?ws.Cells(j, i).DisplayFormat.Interior.ColourIndex 'This will work
?ws.Cells(j, i).DisplayFormat.Interior.ColourIndex.Value 'This will err

另外,你也不需要把它放在括号里,或者:

cond = ws.Cells(j, i).DisplayFormat.Interior.ColourIndex

答:我写的是颜色而不是颜色。