使用VBA在Excel中高亮选中行而不更改颜色

我想用excel表格中的macros来突出显示当前选中的行与模式(不是颜色,因为该行上的某些单元格可能已经着色)。 我已经写了下面的VBAmacros,但是,当一个新的单元格被选中,它重置整个工作表的颜色。 如果它清除了表单上的所有模式(因为没有单元格使用模式进行格式化),但即使指定仅清除模式(使用ActiveSheet.Cells.Interior.Pattern = xlPatternNone ),它也可以清除颜色和边界。

 Private Sub Worksheet_SelectionChange(ByVal Target As Range) 'remove past colors ActiveSheet.Cells.Interior.Pattern = xlPatternNone With Me .Rows(Target.Row).Interior.Pattern = XlPattern.xlPatternChecker End With End Sub 

使用xlPatternAutomatic而不是xlPatternNone 。 请注意,它也将删除网格(但不包括您添加的边框)。