select整个最后一行
我试图让我的代码find工作表中的最后一行,并复制整个行,并粘贴下面。 目前我有:
Cells(Application.Rows.Count, 1).End(xlUp).Select Selection.Copy Cells(Application.Rows.Count, 1).End(xlUp).Offset(1, 0).Select Selection.Insert Shift:=xlDown Application.CutCopyMode = False
find行中的最后一个单元格非常棒,但是当它复制/粘贴时,它只抓取第一个单元格。 所以,我想知道的是,如果您可以使用此代码来查找最后一行,然后select整个行,然后复制/粘贴下面。 请记住,我不能只input
Rows("3:3").Select Selection.Copy Rows("4:4").Select Selection.Insert Shift:=xlDown
因为该行将是可变的。 谢谢!
Dim lastRow As Long lastRow = Cells(Application.Rows.Count, 1).End(xlUp).Row Rows(lastRow).Select Selection.Copy Rows(lastRow).Offset(1, 0).Select Selection.Insert Shift:=xlDown Application.CutCopyMode = False
上面的代码将find最后一行,select它,将其复制并粘贴到下面。 但是,在某些情况下,我需要复制最后一行并将其粘贴到它下面的几行,所以:
Rows("3:3").Select Selection.Copy Rows("4:16").Select Selection.Insert Shift:=xlDown
事情到这一点,但是我不能粘贴选定的行在几行,因为
Rows(lastRow:4).Select
吓坏了。 有没有办法将“16”添加到最后一行,以便复制该行并将其粘贴到接下来的14行等中?
您可以使用.Resize然后填充下来select多个行。
dim rws as long rws = 14 'total # of rows 3:16 with worksheets("sheet1") .cells(.rows.count, "A").end(xlup).resize(rws, .columns.count).filldown end with
你需要调整它的大小
Sub temp() Dim lr As Long lr = Range("A" & Rows.Count).End(xlUp).Row Rows(lr).Copy Range("A" & lr).Resize(14, Columns.Count).PasteSpecial xlPasteAll End Sub
不要select东西,这是非常糟糕的做法。