我想将表中的可见行复制到同一工作簿中的单独工作表中。我有点新使用'ListObject'方法来处理表格(由于几个原因,直接引用表格是我的模块其余部分更好的方法)Excel VBA - 仅复制和粘贴可见表格行
以下是我的最佳尝试,当我运行它时,我得到''Sheets("Sheet8").Range("A1").Paste'
线上的运行时错误'438'',我一直在网上搜索一个小时,试图弄清楚我做错了什么,用它来表示它将复制的数据粘贴到另一个表/表中?任何援助将不胜感激!
感谢,
亚当
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
'.PasteSpecial xlPasteAll'代替'.Paste' –
此担任好,非常感谢! – AdamDynamic