![](/img/trans.png)
[英]change Cell colour based on cell colour of another cell excel 2016
[英]Change the colour of a cell if the user changes the content of that cell
如果用户更改了单元格,则尝试更改单元格的颜色。 目前,它更改了我更改某些内容后选择的下一个单元格。
Private Sub Worksheet_Change(ByVal Target As Range)
If Environ("Username") = "HelloWorld" Then
With ActiveCell.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 7195899
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End If
End Sub
您只需要将“ ActiveCell.Interior”更改为“ Target.Interior”:
Private Sub Worksheet_Change(ByVal Target As Range)
If Environ("Username") = "HelloWorld" Then
With Target.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 7195899
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End If
End Sub
这是因为更改任何单元格后都会触发此子项,因此引用的“ ActiveCell”与“ Target”不同。
编码愉快!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.