在excel中选中某个单元格后该单元格所在的行与列都能高亮颜色显示?

如题所述

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Cells.Interior.Color = xlNone
    If Target.Count > 1 Then
        Exit Sub
    Else
        Target.EntireColumn.Interior.Color = vbGreen
        Target.EntireRow.Interior.Color = vbGreen
    End If
End Sub

右键工作表标签》查看代码,复制粘贴以上代码》关闭新弹出的窗口》回到excel中,点击单元格测试效果~

温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2016-03-03
Private Sub Worksheet_Change(ByVal Target As Range)
If Application.CutCopyMode <> False Then
Application.CutCopyMode = False
End If
Call colorset(Target)
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Application.CutCopyMode = False Then
Call colorset(Target)
Else
Exit Sub
End If
End Sub
Private Sub colorset(ByVal rngtarget As Range)
If rngtarget.Count > 1 Then
Cells.Interior.ColorIndex = 0
Exit Sub
End If
Rows.Interior.ColorIndex = 0
x = ActiveCell.Row
y = ActiveCell.Column
Rows(x).Interior.ColorIndex = 20
Columns(y).Interior.ColorIndex = 35
ActiveCell.Interior.ColorIndex = 15
End Sub
复制以上就可以了本回答被提问者采纳
相似回答