Excel – 选中单元格行列高亮

2019年12月29日13:34:12 发表评论 热度528 ℃

日常生活中,使用 Excel 处理大量数据表单时常常会因为数据量繁杂而不容易锁定自己所需的数据,这时候我们往往希望需要查看的单元格,或者是选中单元格对应的整行整列高亮显示,例如下面这样:

实现代码如下:

  1. Private Sub Worksheet_SelectionChange(ByVal Target As Range)  
  2.    
  3.     Cells.Interior.ColorIndex = 2                     '初始化背景颜色  
  4.     Rows(Target.Row).Interior.ColorIndex = 33         '设置选中的行颜色  
  5.     Columns(Target.Column).Interior.ColorIndex = 33   '设置选中的列颜色  
  6.     Target.Cells.Interior.ColorIndex = 43             '设置选中的单元格颜色  
  7.       
  8. End Sub  

代码中的数值为颜色值,具体颜色值可参照之前的文章>>> Excel~常用颜色对照表 。

效果如下:

Excel - 选中单元格行列高亮

瓜皮猪

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: