人气 5074

高亮显示指定单元格整行和整列 [复制链接]

zzs1808 2017-4-28 17:02:43
当选择单元格时,用指定的颜色高亮显示选定区域左上角单元格整行和整列。
作者:小智雅汇
代码1Private 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 = TrueEnd Sub
代码2Private 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 = TrueEnd Sub以上两种代码均可得到结果
代码描述利用Worksheet_SelectionChange事件,在工作表的单元格选取发生改变时运行指定的程序。
用Union方法得到ActiveCell对象的整行和整行;将Union得到的对象通过.Interior.TintAndShade设置颜色。
过程运行效果

1493369838121616.jpg

1493369838121616.jpg
您需要登录后才可以回帖 登录 | 立即注册

QQ|手机版|精益人 ( 沪ICP备19004111号-1 )|网站地图

GMT+8, 2024-12-22 18:52 , Processed in 0.224485 second(s), 23 queries .

Powered by Lean.ren X3.5 Licensed  © 2001-2030 LEAN.REN