我希望你能幫助運行時錯誤1004
我收到運行時錯誤1004碼,我希望你能幫助
我的代碼如下。
錯誤是發生在lastrow = Sheet1.Cells(Rows.Count, 1).End(x1Up).Row
Sub copycolumns()
Dim lastrow As Long, erow As Long
lastrow = Sheet1.Cells(Rows.Count, 1).End(x1Up).Row
For i = 2 To lastrow
If Sheet1.Cells(i, 6) = "Algiers" Then
Sheet1.Cells(i, 1).Copy
erow = Sheet2.Cells(Rows.Count, 1).End(x1Up).Offset(1, 0).Row
Sheet1.Paste Destination:=Worksheets("Sheet2").Cells(erow, 1)
Sheet1.Cells(i, 3).Copy
Sheet1.Paste Destination:=Worksheets("Sheet2").Cells(erow, 2)
Sheet1.Cells(i, 6).Copy
Sheet1.Paste Destination:=Worksheets("Sheet2").Cells(erow, 3)
End If
Next i
Application.CutCopyMode = False
Sheet2.Columns().AutoFit
Range("A1").Select
End Sub
'x1Up'應該是'xlUp'它應該是小寫字母L不是1 –
謝謝Scott –