该表有两个前两列,我想将它们粘贴到另一个表“table9”中
两个表上的行可能会有所不同,但这是任务的顺序。先清空table9,然后取出table3的前两列,粘贴到table9的前两列。
我在其他问题的帮助中使用以下帮助进行了尝试:
Private Sub CommandButton2_Click() 'ActiveX button's click event handler
Dim lo As ListObject, TABLE_NAME, arr
For Each TABLE_NAME In Array("IndividualProfitLoss|Table9") 'and so on
On Error Resume Next
arr = Split(TABLE_NAME, "|")
Set lo = Me.Parent.Sheets(arr(0)).ListObjects(arr(1))
If Err.Number <> 0 Then
MsgBox TABLE_NAME & " was not found. Check the table name", vbCritical + vbOKOnly, "Sub CommandButton1_Click()"
Exit Sub
End If
On Error GoTo 0
If Not lo.DataBodyRange Is Nothing Then lo.DataBodyRange.Delete
Next
Dim Table3 As ListObject, Table9 As ListObject
Dim h As ListColumn
Set Table3 = Receipt.ListObjects("Table3")
Set Table9 = IndividualProfitLoss.ListObjects("Table9")
'loop over the headers from the source table
For Each h In Table3.ListColumns
'is the column name in the "excluded" list?
If IsError(Application.Match(h.Name, Array("??? ???????", "??????"), 0)) Then
'ok to copy...
h.DataBodyRange.Copy Table9.ListColumns(h.Name).DataBodyRange(1)
End If
Next h
End Sub
这给了我运行时错误424. "Object Required".
任何帮助,将不胜感激
编辑:我相信清除 table9 的代码可以工作,但是将 table3 的前两列的值粘贴到 table9 是一个问题。所以那里的帮助将不胜感激:)