仅复制可见单元格

时间:2014-03-19 11:14:59

标签: excel vba visibility copy-paste

我正在尝试将我的过滤器用于同一本书中的另一张纸后复制可见单元格,但我不确定这段代码。它现在看起来如何:

     Sub Button1_Click()
        Dim i As Integer
        Dim VisRan As Range
        VisRan = Sheets(1).Range("a39:bm29684").SpecialCells(xlCellTypeVisible)
        Visran.Copy   
        Sheets(2).Cells(1, 1).Select
        Selection.Paste

但它不起作用。有什么问题?
Thx提前

1 个答案:

答案 0 :(得分:2)

试试这个:

Sub Button1_Click()
    Dim i As Integer
    Dim VisRan As Range
    On Error Resume Next
    Set VisRan = Sheets(1).Range("a39:bm29684").SpecialCells(xlCellTypeVisible)
    On Error GoTo 0

    If VisRan Is Nothing Then
        MsgBox "There is no visible rows"
        Exit Sub
    End If
    VisRan.Copy Destination:=Sheets(2).Cells(1, 1)
End Sub