0
很多时候我需要在我的Excel工作表上创建条件合并规则,而不是总是在相同的范围内,根据写入的内容设置文本颜色的格式。在Excel上为文本值创建条件合成宏
最常见的情况是将范围内文本“有效”的所有单元格变为绿色和粗体,而“无效”变为红色和粗体。
我试图使用开发工具栏上的记录宏功能来创建这个宏,但它没有工作,代码是空白的。
因为我对VBA没有任何认识,所以我想知道是否有人可以给我一个创建这个宏的帮助。
定义:
- 有没有固定的范围,它需要捕捉选择的范围;
- 基于文本格式,如果“有效”绿色和粗体,如果“无效”红色和粗体。
- 仅限一张纸。
[解决]
Sub EffectiveNot()
'
' EffectiveNot Macro
'
Dim rStart As Range
Set rStart = Selection
Selection.FormatConditions.Add Type:=xlTextString, String:="Effective", _
TextOperator:=xlContains
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Bold = True
.Italic = False
.Color = -11489280
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Selection.FormatConditions.Add Type:=xlTextString, String:="Not effective", _
TextOperator:=xlContains
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Bold = True
.Italic = False
.Color = -16776961
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
End Sub