我想複製粘貼一行值從一個表到另一個,但不斷出現運行時錯誤1004:應用程序定義或對象定義的錯誤。 錯誤是在下面兩個的第一行,我不知道我要去哪裏錯了。複製粘貼範圍在VBA Excel
Set copyRange = Worksheets("Sheet2").range(A & i + 1 & CA & i + 1)
copyRange.Copy Destination:=Cells(countD, 2)
代碼需要一次複製一行並粘貼到默認表單中。
編輯 全碼
Dim List1 As range
Dim List2 As range
Dim lastRow As Integer
Dim countD As Integer
Dim found As Boolean
Dim copyRange As range
Set List1 = ThisWorkbook.Sheets("Sheet1").range("H2:H600")
Set List2 = ThisWorkbook.Sheets("Sheet2").range("I2:I600")
countD = 2
lastRow = Application.CountA(ThisWorkbook.Sheets("Sheet2").range("C:C"))
For i = lastRow To 2 Step -1
found = False
value1 = List1.Item(i, 1)
For Each value2 In List2
If value1 = value2 Then
found = True
Exit For
End If
Next
If found = False Then
Set copyRange = Sheets("Sheet1").range("A" & i + 1 & "CA" & i + 1)
copyRange.Copy Destination:=Cells(countD, 2)
Sheets("Discrepancies").Cells(countD, 1) = "name not found"
ThisWorkbook.Sheets("Sheet1").Cells(i + 1, 1).EntireRow.Delete
Cells(countD, 8).Interior.ColorIndex = 3
countD = countD + 1
End If
Next
嘗試範圍( 「A」 的前面加一個冒號
:
的&I + 1&「CA」&i + 1) – Vasimnope,不起作用,同樣的錯誤代碼 – Intern87
我會建議提供您的完整代碼...以確定實際的錯誤.... – Vasim