最好的方案是用VBA,需要将Excel的格式另存为xlsm,按ALT+F11打开VBA窗口,双击左侧的 Sheet1,在弹出的窗口中粘贴:
Private LastRow As Long
Private LastCol As Long
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rng As Range
Set rng = Range("A1:Z1000") ' ← 改成你的数据区域
Application.ScreenUpdating = False
' 1) 清除上一次的高亮(只清上一行+上一列)
If LastRow <> 0 Then
Intersect(rng, Rows(LastRow)).Interior.Pattern = xlNone
Intersect(rng, Columns(LastCol)).Interior.Pattern = xlNone
End If
' 2) 记录本次位置
LastRow = Target.Row
LastCol = Target.Column
' 3) 画本次的十字高亮
Intersect(rng, Rows(LastRow)).Interior.Color = RGB(220, 230, 241)
Intersect(rng, Columns(LastCol)).Interior.Color = RGB(220, 230, 241)
Application.ScreenUpdating = True
End Sub
如果是想高亮当前行:
Private LastRow As Long
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rng As Range
Set rng = Range("A1:Z1000") ' ←改成你的区域
Application.ScreenUpdating = False
' 清上一次
If LastRow <> 0 Then
Intersect(rng, Rows(LastRow)).Interior.Pattern = xlNone
End If
' 画本次
LastRow = Target.Row
Intersect(rng, Rows(LastRow)).Interior.Color = RGB(220, 230, 241)
Application.ScreenUpdating = True
End Sub
高亮当前列:
Private LastCol As Long
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rng As Range
Set rng = Range("A1:Z1000") ' ←改成你的区域
Application.ScreenUpdating = False
' 清上一次
If LastCol <> 0 Then
Intersect(rng, Columns(LastCol)).Interior.Pattern = xlNone
End If
' 画本次
LastCol = Target.Column
Intersect(rng, Columns(LastCol)).Interior.Color = RGB(220, 230, 241)
Application.ScreenUpdating = True
End Sub