【发布时间】:2009-11-12 22:09:51
【问题描述】:
我有 excel 宏来选择要剪切并粘贴到下一张表的行。现在我想一次选择多行以剪切并粘贴到下一张纸,然后返回上一张纸以删除被剪切的空白行。我对单行剪切和粘贴的代码如下:
Sub CutPasteRows()
Dim iLastRow As Integer
'select the first cell to intiate script
txtRowNum = Selection.Row
'select the row
Rows(txtRowNum).EntireRow.Select
Selection.Cut
'if the active worksheet is the last one (no next worksheet), display error.
If ActiveSheet.Index = Worksheets.Count Then
MsgBox ("There are no next worksheet")
Else
ActiveSheet.Next.Select
iLastRow = ActiveSheet.UsedRange.Rows.Count
'if the workshet is blank, start with the first row. Otherwise, add 1 to the last row
If Cells(1, 1).Value = "" And iLastRow = 1 Then
iLastRow = 1
Else
iLastRow = iLastRow + 1
End If
'Paste row
Rows(iLastRow).EntireRow.Select
ActiveSheet.Paste
'Go back to the last worksheet
ActiveSheet.Previous.Select
Rows(txtRowNum).EntireRow.Select
Selection.Delete
End If
End Sub
感谢任何帮助。
谢谢
【问题讨论】:
-
它做错了什么?错误信息或问题是什么?