如何解决标记和过滤重复 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"
结束子
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。