【发布时间】:2022-07-15 05:17:34
【问题描述】:
我正在尝试将非空白单元格从 sheet1 复制并粘贴到 sheet2。
我收到应用程序/对象错误。
Public Sub CopyRows()
Sheets("Sheet1").Select
FinalRow = Cells(Rows.Count, 1).End(xlDown).Row
For x = 4 To FinalRow
ThisValue = Cells(x, 1).Value
NextRow = Cells(Rows.Count, 1).End(xlDown).Row
If Not IsEmpty(ThisValue) Then
Cells(x, 1).Resize(1, 6).Copy
Sheets(2).Select
Cells(NextRow, 1).Select
ActiveSheet.Paste
Sheets(1).Select
End If
Next x
End Sub
【问题讨论】:
-
一般来说,你想在你的代码中avoid using Select。最好指定给定范围在哪个工作表中(例如:
Sheets(1).Cells(x, 1).Value而不是Cells(x, 1).Value)