如何用条件格式填充整行?
How to fill entire rows with conditional formatting?
我有以下代码:这只填充 a 列中的行,我希望所有列都被填充。
Sheets("Schedule").Cells.Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=m1=""Part"""
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent1
.TintAndShade = 0.399945066682943
End With
我已经select所有细胞都解决了这个问题,但它没有奏效
如果您希望 sheet 中的所有单元格在包含单词 "Part" 时变为蓝色。那么你应该使用这个代码。
Sheets("Schedule").Cells.Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=A1=""Part"""
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent1
.TintAndShade = 0.399945066682943
End With
如果您希望条件从 "M" 列开始,您应该使用此行 Sheets("Schedule").range("M:AAA").select
而不是 Sheets("Schedule").Cells.Select
.
你的公式在
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=M1=""Part"""
不正确。只需使用
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$M1=""Part"""
相反,它会起作用。
注:
这里的区别是 M
前面的 $
确保列是固定的但行 1
不是并且可以迭代。
而且我建议根本不要使用 .Select
和 Selection.
(这是不好的做法,应该 始终 避免)。
您的代码可以这样改进:
With Sheets("Schedule").Cells
.FormatConditions.Add Type:=xlExpression, Formula1:="=$M1=""Part"""
.FormatConditions(.FormatConditions.Count).SetFirstPriority
With .FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent1
.TintAndShade = 0.399945066682943
End With
End With
我有以下代码:这只填充 a 列中的行,我希望所有列都被填充。
Sheets("Schedule").Cells.Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=m1=""Part"""
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent1
.TintAndShade = 0.399945066682943
End With
我已经select所有细胞都解决了这个问题,但它没有奏效
如果您希望 sheet 中的所有单元格在包含单词 "Part" 时变为蓝色。那么你应该使用这个代码。
Sheets("Schedule").Cells.Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=A1=""Part"""
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent1
.TintAndShade = 0.399945066682943
End With
如果您希望条件从 "M" 列开始,您应该使用此行 Sheets("Schedule").range("M:AAA").select
而不是 Sheets("Schedule").Cells.Select
.
你的公式在
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=M1=""Part"""
不正确。只需使用
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$M1=""Part"""
相反,它会起作用。
注:
这里的区别是 M
前面的 $
确保列是固定的但行 1
不是并且可以迭代。
而且我建议根本不要使用 .Select
和 Selection.
(这是不好的做法,应该 始终 避免)。
您的代码可以这样改进:
With Sheets("Schedule").Cells
.FormatConditions.Add Type:=xlExpression, Formula1:="=$M1=""Part"""
.FormatConditions(.FormatConditions.Count).SetFirstPriority
With .FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent1
.TintAndShade = 0.399945066682943
End With
End With