最好的方案是用VBA,需要将Excel的格式另存为xlsm,按ALT+F11打开VBA窗口,双击左侧的 Sheet1,在弹出的窗口中粘贴:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
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 |
如果是想高亮当前行:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
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 |
高亮当前列:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
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 |

马春杰杰



最新评论
站长您好,亚马逊云咨询推广资源,望建立联系,可邮件,谢谢。
换友情链接吗?
看你的站做的挺不错的
恭喜!!太强了,硕博连读啊
雁过留毛,人过留名。
看不懂但大受震撼
每天都在战争,希望2026和平.
ZeroTier 看过多篇帖子,目前群辉、飞牛os、win11 、安卓、ubuntu ≥18.04 顺利通过,这篇相对于简单 实用、特来感谢 🙄