条件格式:全局格式定义?
可以说我有Sheet1在哪里
AB 1 foo foo 2 bar bar
和ReferenceSheet在哪里
A 1 bar <-- cell is formatted with red background 2 foo <-- cell is formatted with blue background
和所有其他编程示例一样,“bar”和“foo”是任意占位符值。 🙂
我想要使Sheet1中的每个单元格(A1:D4)与ReferenceSheet(A1:A2)中定义单元格的值相匹配,单元格将自动复制定义单元格的格式。
因此,继续上面的例子,Sheet1的背景颜色将被格式化为
AB 1 bl bl 2 red red
但是,如果我将参考手册的格式更改为
A 1 bar <-- cell is formatted with pink background 2 foo <-- cell is formatted with black background
Sheet1的背景格式将更新为
AB 1 blk blk 2 pk pk
如果可能的话,怎么去实现呢?
======
*我想定义我的格式在工作表(而不是在Visual Basic代码),以创build更多的用户可访问的格式定义。 如果这不是一个选项,Visual Basic(以及全局)定义将是我的下一个select。 应用于每个单元格的批量复制的条件格式将是我的最后一个select,尽pipefind类似于Microsoft Word中的样式的样式抽象选项将使其成为一个更可选的select。
Worksheet_Change Sub
将会做你正在寻找的东西:
Private Sub Worksheet_Change(ByVal Target As Range) 'Place Sub in only the Reference Worksheet 'Do nothing if more than one cell is changed or content deleted If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub With Sheets("Sheet1").Range("DefineRange").FormatConditions.Modify(Type:=xlCellValue, Operator:=xlEqual, Formula1:="=" & Target.Value) .Interior.Color = Target.Interior.Color End With End Sub
编辑:我用.Modify
因为我认为你已经有一个条件格式指定,如果一个单元格等于一定的值。 如果要添加新的条件格式规则,请使用.Add
。