在excel中,如何使选到的单元格呈现某种颜色,在上下左右移动时也跟着出现颜色,这样移动起来好辨认

2024-11-01 05:41:20
有3个网友回答
网友(1):

右击工作表标签,从弹出的快捷菜单中选择:“查看代码”,或者按下Alt+F11组合键,进入VBA代码窗口,键入如下代码:(代码有以下几种,可根据用户的需要进行选择,不够都有个缺点就是不能在本工作表内无法进行复制粘贴操作,若有哪位知道的话,请留言告诉我下,学习学习!)
一、行列都变色,可填充,不能复制,可多行多列变色、可不断变化各种色彩(推荐使用)
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
On Error Resume Next
Cells.FormatConditions.Delete
iColor = Int(50 * Rnd() + 2)
With Target.EntireRow.FormatConditions
.Delete
.Add xlExpression, , "TRUE"
.Item(1).Interior.ColorIndex = iColor
End With
With Target.EntireColumn.FormatConditions
.Delete
.Add xlExpression, , "TRUE"
.Item(1).Interior.ColorIndex = iColor
End With
End Sub
二、行变色,可填充,不能复制,可多行变色、可不断变化各种色彩(推荐使用)
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
On Error Resume Next
Cells.FormatConditions.Delete
With Target.EntireRow.FormatConditions
.Delete
.Add xlExpression, , "TRUE"
.Item(1).Interior.ColorIndex = Int(50 * Rnd() + 2)
End With
End Sub
三、列变色,可填充,不能复制,可多列变色、可不断变化各种色彩(推荐使用)
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
On Error Resume Next
Cells.FormatConditions.Delete
With Target.EntireColumn.FormatConditions
.Delete
.Add xlExpression, , "TRUE"
.Item(1).Interior.ColorIndex = Int(50 * Rnd() + 2)
End With
End Sub
四、单元格变色,可填充,不能复制,可多格变色、可不断变化各种色彩(推荐使用)
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
On Error Resume Next
Cells.FormatConditions.Delete
With Target.FormatConditions
.Delete
.Add xlExpression, , "TRUE"
.Item(1).Interior.ColorIndex = Int(50 * Rnd() + 2)
End With
End Sub
五、行变色,可填充,不能复制,可多行变色
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
On Error Resume Next
Cells.FormatConditions.Delete
With Target.EntireRow.FormatConditions
.Delete
.Add xlExpression, , "TRUE"
.Item(1).Interior.ColorIndex = 7
End With
End Sub
六、行、列都变色,不可填充,不能复制,只能单行单列变色
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Cells.Interior.ColorIndex = xlNone
Rows(Target.Row).Interior.ColorIndex = 6
Columns(Target.Column).Interior.ColorIndex = 6
Cells(Target.Row, Target.Column).Interior.ColorIndex = 33
End Sub
七、行变色,不可填充,不能复制,只能单行变色
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Cells.Interior.ColorIndex = xlNone
Rows(Target.Row).Interior.ColorIndex = 6
Cells(Target.Row, Target.Column).Interior.ColorIndex = 33
End Sub
八、列变色,不可填充,不能复制,只能单列变色
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Cells.Interior.ColorIndex = xlNone
Columns(Target.Column).Interior.ColorIndex = 6
Cells(Target.Row, Target.Column).Interior.ColorIndex = 33
End Sub

网友(2):

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Cells.Interior.ColorIndex = 0
Rows(Target.Row).Interior.ColorIndex = 20
Columns(Target.Column).Interior.ColorIndex = 20
End Sub

网友(3):

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Cells.Interior.ColorIndex = xlNone
Target.Interior.ColorIndex = 23
End Sub