您现在的位置是:首页 > Excel技巧>高亮显示指定单元格整行和整列
wps高亮显示选中单元格的整行整列-高亮显示指定单元格整行和整列
发布于2022-04-150人已围观
当选择单元格时,用指定的颜色高亮显示选定区域左上角单元格整行和整列。
作者:小智雅汇
代码1
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.ScreenUpdating = False
Dim highLightRng As Range
Dim rng1 As Range
Dim rng2 As Range
Cells.Interior.ColorIndex = xlNone
Set rng1 = Rows(ActiveCell.Row)
Set rng2 = Columns(ActiveCell.Column)
On Error Resume Next
Set highLightRng = Application.Union(rng1, rng2)
highLightRng.Interior.ThemeColor = xlThemeColorAccent3
highLightRng.Interior.TintAndShade = 0.799981688894314
Set rng1 = Nothing
Set rng2 = Nothing
Set highLightRng = Nothing
' ActiveCell.Value = ActiveCell.Address
Application.ScreenUpdating = True
End Sub
代码2
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.ScreenUpdating = False
Cells.Interior.ColorIndex = -4142
Columns(Target.Column).Interior.ColorIndex = 20
Rows(Target.Row).Interior.ColorIndex = 20
Application.ScreenUpdating = True
End Sub
以上两种代码均可得到结果
代码描述
利用Worksheet_SelectionChange事件,在工作表的单元格选取发生改变时运行指定的程序。
用Union方法得到ActiveCell对象的整行和整行;
将Union得到的对象通过.Interior.TintAndShade设置颜色。
过程运行效果
- 上篇文章:Excel固定表头与表尾
- 下篇文章:Excel自动添加目录链接、自动删除全部超级链接
相关文章
文章评论
- 这篇文章还没有收到评论,赶紧来抢沙发吧~