C3:H7内单元格默认填充内容为【无】,黑色字体无底色,当某个格子内【无】修改成【1#设备故障】的时候,【1#设备故障】字体加粗变成红色,同时单元格底色填充其他颜色,没有修改的不变
请用鼠标右键单击工作表标签,选择“查看代码”,下拉“通用”下选择"Worksheet",下拉"声明"选择“Change",在代码框中插入下列代码:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column > 2 And Target.Column < 9 And Target.Row > 2 And Target.Row < 9 Then
Target.Select
If Target = "1#设备故障" Then
With Selection.Font
.Color = -16776961
.TintAndShade = 0
End With
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Selection.Font.Bold = True
Else
Target.Select
With Selection.Font
.ColorIndex = xlAutomatic
.TintAndShade = 0
End With
With Selection.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Selection.Font.Bold = False
End If
End If
End Sub
保存为启用宏的工作簿 格式即可实现你的要求。
这种小事用不到VBA,用条件格式就可以做到
本回答被提问者采纳