复制 .SpecialCells(xlCellYypeVisible)

Copy .SpecialCells(xlCellYypeVisible)

谁能告诉我为什么这段代码也在复制 none 可见数据。

    Sub Copy ()
    Range(ActiveCell,ActiveCell.Offset(LIRS_Required,7)).SpecialCells(xlCellTypeVisible, xlTextValues).Copy
    End Sub

我只想要 table 过滤后的可见数据。

此致

这是因为 .offset() 不会跳过隐藏的单元格。

试试这个解决方法:

Sub Copy()
    Dim rng As Range
    Set rng = ActiveCell.Resize(LIRS_Required + 1)
    While rng.SpecialCells(xlCellTypeVisible).Count < LIRS_Required + 1
        Set rng = rng.Resize(rng.Count + LIRS_Required + 1 - rng.SpecialCells(xlCellTypeVisible).Count)
    Wend
    rng.Resize(, 7 + 1).SpecialCells(xlCellTypeVisible).Copy
End Sub