我试图仅将表中的可见行复制到同一工作簿中的单独工作表中。我对使用“ListObject”处理表的方法有点陌生(出于一些原因,就我的模块的其余部分而言,直接引用表是一种更好的方法)
下面是我最好的尝试,当我运行它时,我得到'运行时错误'438'' 'Sheets("Sheet8").Range("A1").Paste'
,我已经在互联网上搜索了一个小时试图找出我做错了什么,我该怎么做需要重新措辞,以便将复制的数据粘贴到另一个工作表/表格中?任何援助将不胜感激!
谢谢,
亚当
Private Sub CopyVisibleAreaOfTable(ByVal TableName As String)
Const FN_NAME As String = "CopyVisibleAreaOfTable"
On Error GoTo catch
Dim TargetTable As ListObject
Dim NumberOfAreas As Long
Set TargetTable = Sheets("Adj1").ListObjects(TableName)
' Check that there are fewer than 8192 seperate areas
With TargetTable.ListColumns(1).Range
NumberOfAreas = .SpecialCells(xlCellTypeVisible).Areas(1).Cells.Count
Debug.Print NumberOfAreas
End With
If NumberOfAreas = 0 Then
'Do something to trigger an error message
Else
TargetTable.Range.SpecialCells(xlCellTypeVisible).Copy
Sheets("Sheet8").Range("A1").Paste
Application.CutCopyMode = False
End If
finally:
Exit Sub
catch:
Call ErrorReport(FN_NAME, True, Err.Number, Err.Description, "Table Name: " & TableName)
Resume finally
End Sub