Excel-VBA-如何突出显示表格中的目标行?

问题描述 投票:0回答:1

以下代码可突出显示

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

问题: 如何突出显示目标行?

excel vba row listobject
1个回答
0
投票

使用

Intersect

Dim rng As Range
Set rng = Intersect(Target.EntireRow, oList.DataBodyRange)

If Not rng Is Nothing Then
    rng.Interior.ColorIndex = 38
End If
© www.soinside.com 2019 - 2024. All rights reserved.