如何用vba控制excel单元格内数值的颜色?

2024-11-16 04:19:06
推荐回答(2个)
回答(1):

使用VBA事件:

VBA编辑框中,点击工作表,输入如下代码。

Private Sub Worksheet_Change(ByVal Target As Range)
Target.Interior.Color = vbRed
End Sub

回答(2):

Dim a, b, c, d, e, f

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
a = Cells(ActiveCell.Row, ActiveCell.Column).Value
b = ActiveCell.Row
c = ActiveCell.Column

If d = "" And e = "" And f = "" Then
d = a
e = b
f = c
Else
If d = Cells(e, f).Value Then
e = b
f = c
Else
Cells(e, f).Font.Color = -16776961
e = b
f = c
End If
End If
d = Cells(e, f).Value

End Sub