简体   繁体   中英

Insert Row and Copy and Paste Values

I have a "status" type of report that pulls in a from a variety of sources onto a single worksheet. My end goal is to essentially keep a log of each entry. So I created a macro that will copy the range from Sheet8, insert a new row on Sheet11, and then paste the row into Sheet11. Additionally, I added a line to remove the excel selection. My issue is the paste is pasting the formula, not the values. How do have it paste the values of the cells in Sheet8 onto Sheet11?

Sub copyRowToBelow()
On Error GoTo Err_Execute
    Sheet8.Range("A2:L2").Copy
    Sheet11.Range("A2").Rows("2:2").Insert Shift:=xlDown
    Sheet8.Range("A2:L2").Select
    Application.CutCopyMode = False

Err_Execute:
    If Err.Number = 0 Then MsgBox "All have been copied!" Else _
    MsgBox Err.Description
End Sub

You could shift down first, then copy the data by setting the two rows' values equal to one another.

Also, do you mean to only shift one cell down? Not that entire row? My code below shifts the entire row below row 2 down.

Sub copyRowToBelow()
On Error GoTo Err_Execute
    Sheet11.Range("A2").Rows("2:2").EntireRow.Insert Shift:=xlDown
    Sheet11.Range("A3:L3").Value = Sheet8.Range("A2:L2").Value

Err_Execute:
    If Err.Number = 0 Then MsgBox "All have been copied!" Else _
    MsgBox Err.Description
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM