2024年1月27日发(作者:)
EXCEl选中变色
[EXCEL]加亮显示选中单元格的所在行与列
我们经常会遇到这种情况,当某条记录有较多字段时,我们选中了这一行或这一行的某个单元格,要查看该记录的其它内容时,常常会感到眼睛比较累,有时还会看走眼,看到其它的记录行去了.如果能让选中的这一行突出显示出来,以区别于其它记录行,就不会出现这种情况了.这样,在工作表中进行选择时,也会感到较为轻松。
为了能够突出显示被选单元格所在行,我们就需要知道该单元格所在的行号,再依此改变该行部分或全部单元格的填充颜色即可.要实现这一功能,就要借助于VBA和单元格的条件格式功能了。
右击工作表标签,从弹出的快捷菜单中选择:“查看代码”,或者按下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 Conditions
.Delete
。Add xlExpression, , "TRUE"
.Item(1)。Interior。ColorIndex = iColor
End With
With Target。Conditions
.Delete
.Add xlExpression, , "TRUE”
.Item(1).ndex = iColor
End With
End Sub
二、行变色,可填充,不能复制,可多行变色、可不断变化各种色彩(推荐使用)
Private Sub Worksheet_SelectionChange(ByVal Target As )
On Error Resume Next
With Row。FormatConditions
.Delete
。Add xlExpression, , "TRUE”
.Item(1)。ndex = Int(50 * Rnd() + 2)
End With
End Sub
三、列变色,可填充,不能复制,可多列变色、可不断变化各种色彩(推荐使用)
Private Sub Worksheet_SelectionChange(ByVal Target As Excel。Range)
On Error Resume Next
Conditions。Delete
With Conditions
。Delete
。Add xlExpression, , "TRUE”
EXCEl选中变色
.Item(1)。Interior。ColorIndex = Int(50 * Rnd() + 2)
End With
End Sub
四、单元格变色,可填充,不能复制,可多格变色、可不断变化各种色彩(推荐使用)
Private Sub Worksheet_SelectionChange(ByVal Target As )
On Error Resume Next
Cells。
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。
With Target。Conditions
。Delete
。Add xlExpression, , "TRUE"
。Item(1)。Interior。ColorIndex = 7
End With
End Sub
六、行、列都变色,不可填充,不能复制,只能单行单列变色
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
or。ColorIndex = xlNone
Rows().Interior。ColorIndex = 6
Columns(Target。Column)。Interior。ColorIndex = 6
Cells(, Target。Column)。ndex = 33
End Sub
七、行变色,不可填充,不能复制,只能单行变色
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Cells。ndex = xlNone
Rows()。ndex = 6
Cells(Target。Row, )。Interior。ColorIndex = 33
End Sub
八、列变色,不可填充,不能复制,只能单列变色
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Cells。Interior。ColorIndex = xlNone
Columns(Target。Column)。ndex = 6
Cells(, )。Interior。ColorIndex = 33
End Sub
发布者:admin,转转请注明出处:http://www.yc00.com/web/1706345228a1451438.html
评论列表(0条)