标记和过滤重复 ListObject VBA

问题描述

我试图在 ListObject(动态表的列)VBA 中查找、标记和过滤重复项,但没有成功。 以下脚本适用于常规范围,我做了一些更改并需要它用于列表对象。 我将非常感谢您的帮助

S

sub Duplicates()
    
    ActiveSheet.Shapes("shape3").Select 'change to whatever your shape is called
    If Selection.ShapeRange.Fill.Visible = msoFalse Then
    Selection.ShapeRange.Fill.Visible = msoTrue
    Selection.ShapeRange.Fill.solid
    Selection.ShapeRange.Fill.ForeColor.SchemeColor = 40
    Else
    
    Selection.ShapeRange.Fill.Visible = msoFalse
    
    End If
    
    Dim Rng As Range
    Dim cel As Range
    
    'Test for duplicates in a single column
    'Duplicates will be highlighted in red
    
    Set Rng = Range(Range("B1"),Range("B" & Rows.Count).End(xlUp))
    
    For Each cel In Rng
    If WorksheetFunction.CountIf(Rng,cel.Value) > 1 Then
    
    cel.Interior.ColorIndex = 3
    End If
    Next cel
    
    Range("B:J").Select
    
    ActiveSheet.Range("$B$1:$J$1").AutoFilter Field:=1,Criteria1:=RGB(255,0 _,0),Operator:=xlFilterCellColor
    ActiveWindow.SmallScroll Down:=-9
    ActiveSheet.Range("$B$1:$J$1").AutoFilter Field:=9,Criteria1:="<>0",_
    Operator:=xlAnd

End Sub

解决方法

一种方法是使用条件格式:

type FOO_TYPE = typeof FOO;

/*
  FOO_TYPE would give the type of entire object:

  readonly a: {
    readonly label: "aa";
    readonly value: "aaa";
  };
  readonly b: {
    readonly label: "bb";
    readonly value: "bbb";
  };
  readonly c: {
    readonly label: "cc";
    readonly value: "ccc";
  };
*/

// all the keys in FOO
type FOO_KEYS = keyof FOO_TYPE; // "a" | "b" | "c" | "d"

// all the keys except c and d
type EXCLUDED_KEYS = Exclude<FOO_KEYS,'c' | 'd'>; // "a" | "b"

// enforce the assignment
const BAR: FOO_TYPE[EXCLUDED_KEYS]['label'] = 'aa'; // "aa" | "bb"

结束子

Before After After (ResetFilter)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...