下面的代码突出显示两个表ListObject(1)
和ListObject(2)
中的目标行和列,同时清除所有隐藏行(注意:ListObject(1)
正上方ListObject(2)
)
Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim oList1 As ListObject
Dim oList2 As ListObject
Dim rng As Range
Set oList1 = Me.ListObjects(1)
' Contains hidden rows when filter is applied
Set oList2 = Me.ListObjects(2)
' Only proceed if `Target` is inside the table body
If Intersect(Target, oList2.DataBodyRange) Is Nothing Then Exit Sub
Application.ScreenUpdating = False
'Clear the color of all cells
Me.Cells.Interior.ColorIndex = 0
' Highlights columns
Set rng = Intersect(Target.EntireColumn, oList1.DataBodyRange)
If Not rng Is Nothing Then
rng.Interior.ColorIndex = 24
End If
' Highlights columns
Set rng = Intersect(Target.EntireColumn, oList2.DataBodyRange)
rng.Interior.ColorIndex = 24
' Highlights rows
Set rng = Intersect(Target.EntireRow, oList2.DataBodyRange)
rng.Interior.ColorIndex = 38
' Clears all hidden rows
For Each oRow In oList2.ListRows
If oRow.Range.EntireRow.Hidden Then
oRow.Range.Interior.ColorIndex = 0
End If
Next oRow
Application.ScreenUpdating = True
End Sub
字符串
**问题:**如何在ListObject(2)
上高亮显示隐藏行中的目标列?
编辑1:
试图在清除隐藏行后突出显示隐藏的目标列。但我得到一个Run-time error '91': Object variable or With block variable not set
Dim oCol As ListColumn
' Clear hidden row and recolor hidden target column
For Each oRow In oList2.ListRows
If oRow.Range.EntireRow.Hidden Then
With Target
oCol.Range.Interior.ColorIndex = 24
End With
End If
Next oRow
型
1条答案
按热度按时间y1aodyip1#
您可以将颜色格式“重新应用”到隐藏行中的列:
字符串