PasteSpecial不工作

我有一个子查找与一个表中的值的数组匹配的值的SolutionID列,然后将其复制到另一个。

不过,我用.PasteSpecial方法.PasteSpecial

对象不支持这个属性或方法

有人知道我在做什么错吗? 谢谢。

 Private Sub CopySolutions(ByRef SourceTable As ListObject, ByRef DestinationTable As ListObject, ByRef values() As String) On Error Resume Next Dim i, j As Integer ' Dummy for looping '** Loop through all of the ID's to copy... *' For i = LBound(values) To UBound(values) With SourceTable.DataBodyRange For j = 1 To .Rows.Count If .Cells(j, 1).Value = values(i) Then .Rows(j).Copy ' Copy the row in the SourceTable Dim LastRow As Integer LastRow = DestinationTable.Rows.Count ' Work out the number of rows in the DestinationTable '** Check to see if the last row in the destination table is already empty '* If DestinationTable.DataBodyRange.Cells(LastRow, 1).Value <> "" Or LastRow = 0 Then DestinationTable.ListRows.Add AlwaysInsert:=True ' Insert a new row in to the DestinationTable LastRow = LastRow + 1 ' Increment LastRow to take in to account the newly added row End If DestinationTable.DataBodyRange.Cells(LastRow, 1).Select ' Select the last row, column 1 in the Destination Table Selection.PasteSpecial Paste:=xlPasteValues, _ Operation:=xlNone, _ SkipBlanks:=False, _ Transpose:=False ' Paste the copied row Exit For ' Exit the For, there is no need to keep checking for matches End If Next End With Next If Err.Number <> 0 Then Call ErrorOutput("An error occured while copying your selected solutions.") End If On Error GoTo 0 WS.Range("Solution").Select ' Reselect the Solution cell range End Sub 

最好避免全部复制/粘贴:

 Dim rngSrc as Range '... Set rngSrc = .Rows(j) '... DestinationTable.DataBodyRange.Cells(LastRow, 1). _ Resize(1, rngSrc.Columns.Count).Value = rngSrc.Value 

尝试这个:

 SourceTable.DataBodyRange.Rows(j).Copy DestinationTable.DataBodyRange.Range("A" & CStr(lastRow)) 

你find最后一排当然。 这样你就不必使用。select