Excel VBA行突出显示

我find了一些如何突出显示当前所选单元格的例子。 我的问题是,我只需要在第3行和更高的行。

这是我迄今拿起的:

Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.Cells.Count > 1 Then Exit Sub Application.ScreenUpdating = False Cells.Interior.ColorIndex = 0 With Target .EntireRow.Interior.ColorIndex = 8 End With Application.ScreenUpdating = True End Sub 

这工作广告,但我正在努力如何不失去我的行1和2行标题单元格的背景颜色。我相信它需要某种“如果”,但我不知道我需要在哪里把它。

另外,无论如何,我可以将其应用于整个工作簿? 我在工作簿中有60张,如果我不能复制代码60次,那将是理想的。

任何帮助是极大的赞赏。

下面的代码将做的伎俩:

 Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range) If Target.Cells.Count > 1 Then Exit Sub If Target.Row <> 1 and Target.Row <> 2 Then Application.ScreenUpdating = False Cells.Interior.ColorIndex = 0 Range("A1:AF2").Interior.ColorIndex = 47 Target.EntireRow.Interior.ColorIndex = 8 Application.ScreenUpdating = True End If End Sub 

你把它放在ThisWorkbook而不是特定的工作Sheet

代码:

 If Target.Row <> 1 and Target.Row <> 2 Then 

检查Target.Row是否不等于Row 1 and 2