我有一個子查找與一個表中的值的數組匹配的SolutionID列中的值,然後將其複製到另一個表中。PasteSpecial不工作
不過,我打一個錯誤與.PasteSpecial
方法 -
對象不支持此屬性或方法
有誰知道我做錯了什麼?謝謝。你會發現,當然最後一行之後
SourceTable.DataBodyRange.Rows(j).Copy DestinationTable.DataBodyRange.Range("A" & CStr(lastRow))
:
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
移動'.Rows(J).Copy'只是其中粘貼前行。 Excel有清除剪貼板的習慣 –
當然,這似乎工作。謝謝。 –