Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 145
  • Last Modified:

Copy and paste values to another location.

I need to copy and paste values from C5:H12 and paste them in C20:H27. But before I do that I need to shift the values in C20:H27 to C35:H42. I have to do this all the way down to C95:H102. I have 7 matrices that I need to shift down starting from C5:H12. The values in the last matrix C95:H102 are to be wiped out since there are no matrices below that. Is there an easy way to write a macro to do this? I need to move all these values and then put 0's in the C5:H12 matrix after everything is shifted down.
Lawrence Salvucci
Lawrence Salvucci
1 Solution
Try this code

Sub Macro2()
    Selection.Insert Shift:=xlDown
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "0"
    Selection.AutoFill Destination:=Range("C5:H5"), Type:=xlFillDefault
    Selection.AutoFill Destination:=Range("C5:H12"), Type:=xlFillDefault
    Selection.Delete Shift:=xlUp
End Sub
Lawrence SalvucciInformation Technology ManagerAuthor Commented:
That didn't work. First question I have about your code is the first range shows C5:H19. Shouldn't that be C5:H12?

When I try to run it I get this error message:

This operation is not allowed. The operation is attempting to shift cells in a table on your worksheet.

I want to copy the values, not shift them. Is that different?
Rob HensonIT & Database AssistantCommented:
Are you copying values or copying formulas?

Do you have values/data in the ranges between the Matrices eg rows 13 to 19 or 28 to 34? Also are they equally spaced?

If no values between and equally spaced, you could copy the range as a block from the first matrix down to the last but one matrix and then copy and paste down to the second matrix. Thus First matrix goes to second matrix position and last but one overwrites the last matrix.

If you have values/data between the matrices, set up a range off to one side which has formulas pulling the value from the previous matrix, ie rows for second matrix link to first matrix, third matrix has formulas linking to rows for second matrix etc. This would then have blank rows between the matrices. This could then be copied and pasted as values using the skip blanks option in the Paste Special window.

Rob H

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now