EXCEL工具栏一定要有 开发工具,没有的看下图1,有的直接跳图2

上图为图1

上图为图2

上图为图3
具体代码在下面,自己复制上去,就有效了
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim i As Integer
Dim j As Integer
Dim lastRow As Long, lastCol As Long
' 清除之前的颜色
Cells.Interior.ColorIndex = xlNone
' 获取最大范围
lastRow = Cells(Rows.Count, Target.Column).End(xlUp).Row
lastCol = Cells(Target.Row, Columns.Count).End(xlToLeft).Column
' 高亮当前行
Rows(Target.Row).Interior.Color = RGB(255, 255, 0)
' 高亮当前列
Columns(Target.Column).Interior.Color = RGB(255, 255, 0)
End Sub