在Excel VBA中选择了SpecialCells(xlCellTypeVisible)额外的行

时间:2020-04-22 18:03:28

标签: excel vba

image1 image2

大家好,

当前在SpecialCells(xlCellTypeVisible)上工作,在过滤数据之后,单元格将以绿色突出显示,如图1所示,但是当使用公式时,也会选择行号。

我需要获取可见单元格的结果将突出显示,没有添加额外的行,如图2所示。

下面是使用的公式。

OB2.ActiveSheet.UsedRange.Offset(1, 0).SpecialCells(xlCellTypeVisible).Rows.Select
        With Selection.Interior
            .Pattern = xlSolid
            .PatternColorIndex = xlAutomatic
            .ThemeColor = xlThemeColorAccent6
            .TintAndShade = 0.399975585192419
            .PatternTintAndShade = 0
        End With

1 个答案:

答案 0 :(得分:1)

我们尝试使用.Offset(1,0)删除标题。但是,这会在底部增加一行。考虑:

Sub RemoveHeaderRow()
    Dim tablee As Range
    Dim tableeBody As Range

    Set tablee = Range("A1").CurrentRegion
    Set tableeBody = tablee.Offset(1, 0).Resize(tablee.Rows.Count - 1, tablee.Columns.Count)

    tableeBody.Select
End Sub

enter image description here

这是要在SpecialCells上使用的范围。