如何在指定的列中更改单元格颜色?
当Ativecell在6行后面时,我选择了此代码以选择和更改整体的内部颜色(绿色)。
我需要选择并更改该行的“ I”和“ J”列的内部颜色(颜色= 9359529)。与此代码相似,但不需要整个行,只有列I和J。
Dim lTarget As Range
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Row >= 6 Then
If Not lTarget Is Nothing Then
lTarget.EntireRow.Interior.ColorIndex = 0
End If
Target.EntireRow.Interior.Color = 9359529
Set lTarget = Target
End If
End Sub
I picked up this code to select and change the interior color (green) of the EntireRow when the AtiveCell is behind the 6 Row.
I need to select and change the interior color (Color = 9359529) of the column "I" and "J" of the Row where is the ActiveCell. Is similar to this code but do not need the entire row, just the columns I and J.
Dim lTarget As Range
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Row >= 6 Then
If Not lTarget Is Nothing Then
lTarget.EntireRow.Interior.ColorIndex = 0
End If
Target.EntireRow.Interior.Color = 9359529
Set lTarget = Target
End If
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
仅使用您的榜样,我认为这是做我想过的最简单方法。
您要么在选择中只有一行 - 要么只想更改第一行
以使用范围对象 - 但这很容易理解
Using just your example and what I think you're asking this is the simplest way to do what I think you're asking.
You either have just one row in the selection - or you just want the first row changed
This can be changed to use a Range object - but this is easy to understand
工作表 SelectionChange
A Worksheet SelectionChange