在Excel中突出显示活动单元而不重置现有填充单元格

如何自动突出显示活动单元格突出显示的整个行,而不会删除突出显示的其他单元格? (我想在存在活动单元格的情况下突出显示整行,然后在离开时取消突出显示。)

我知道下面的VBA代码,但它消除了所有其他单元格填充颜色。

Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.Cells.Count > 1 Then Exit Sub Application.ScreenUpdating = False ' Clear the color of all the cells Cells.Interior.ColorIndex = 0 With Target ' Highlight the entire row and column that contain the active cell .EntireRow.Interior.ColorIndex = 8 End With Application.ScreenUpdating = True End Sub 

您可以使用Conditional Formatting和简单的VBA Event 。 按着这些次序:

在Excel中:
1.当你想要突出显示行时select范围…在这个例子中A1:J20
2.转到菜单>>首页>>条件格式>>新规则… >>使用公式来确定要格式化的单元格
3.在公式文本框中写下这个公式: =CELL("row") = ROW(A1)
4.按“格式化…”button,设置格式化过时
5.按确定

你为之做出上述动作的表单模块的VBA中使用这个事件:

 Private Sub Worksheet_SelectionChange(ByVal Target As Range) Target.Calculate End Sub