以下代码可突出显示
ListObject(2)
中的第 1 行
Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count < 1 Then Exit Sub
Application.ScreenUpdating = False
'Clear the color of all cells
Cells.Interior.ColorIndex = 0
Set oList = ActiveSheet.ListObjects(2)
With Target
'Highlight row and column of the selected cell
.EntireColumn.Interior.ColorIndex = 24
oList.ListRows(1).Range.Interior.ColorIndex = 38
End With
End Sub
问题: 如何突出显示目标行?
使用
Intersect
:
Dim rng As Range
Set rng = Intersect(Target.EntireRow, oList.DataBodyRange)
If Not rng Is Nothing Then
rng.Interior.ColorIndex = 38
End If