利用VBA函数使某一列表格中的数据满足某一条件的单元格字体自动变为红色。

如题所述

选取后,整列变红,自己根据你的条件修改一下就可以了
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
On Error Resume Next
Application.ScreenUpdating = False
Cells.FormatConditions.Delete
With Target.EntireColumn.FormatConditions
.Delete
.Add xlExpression, , "TRUE"
.Item(1).Interior.ColorIndex = 3

End With
Application.ScreenUpdating = True
End Sub
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-11-17
如果填入数据时检查是
Private Sub Worksheet_Change(ByVal Target As Range)
Dim m As Integer
Dim c As Range

m = 1 '要检测的列(A是1,B是2...)
If Target.Count > 1 Then Exit Sub
For Each c In Target.Cells
If c.Column = m Then
If c.Value > 0 Then '(变化的条件大于0,可以是你要求的)
c.Font.Color = vbRed
End If
End If
Next
End Sub
如果不是,具体什么时候检查,还是有数据后点按钮检测
第2个回答  2010-11-17
还不如直接用条件格式方便些?
相似回答