[英]Excel vba paste on last row of data
我需要在vba上的粘贴命令上进行一些代码修改,但问题是它将粘贴到数据的最后一行
即时通讯使用此代码,并且可以正常工作,但是当即时通讯尝试复制另一数据时,它将替换当前数据
Range(Range("A2:L2" & lastrow), ActiveCell.End(xlDown)).PasteSpecial
更改为
Range(Range("A2:L2" & lastrow), ActiveCell.End(xlDown)).offset(1,0).PasteSpecial
尝试使用.Insert
Sub Macro2()
Rows("6:6").Copy
Rows("15:15").Insert Shift:=xlDown
End Sub
首先,您的一行代码并没有太大帮助,复制行也应该存在...
然后 :
Range(Range("A2:L2" & lastrow), ActiveCell.End(xlDown)).PasteSpecial
如果复制了要粘贴的区域,则无需选择单元格区域,只需选择要粘贴的第一个单元格即可!
因此,最重要的部分是复制!
您的代码应如下所示:
With ThisWorkBook.Sheets("SheetToCopy")
If Application.WorksheetFunction.CountA(.Cells) <> 0 Then
LastRow = .Cells.Find(What:="*", _
After:=.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
Else
LastRow = 1
End If
.Range("A2:L" & LastRow).Copy
End With
With ThisWorkBook.Sheets("SheetToPaste")
If Application.WorksheetFunction.CountA(.Cells) <> 0 Then
LastRow = .Cells.Find(What:="*", _
After:=.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
Else
LastRow = 1
End If
.Range("A" & LastRow + 1).PasteSpecial
End With
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.