Solved

Copy and paste values to another location.

Posted on 2014-03-25
3
139 Views
Last Modified: 2014-04-14
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.
0
Comment
Question by:Lawrence Salvucci
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 3

Accepted Solution

by:
Sreeram earned 500 total points
ID: 39952959
Try this code

Sub Macro2()
    Range("C5:H19").Select
    Selection.Copy
    Range("C5").Select
    Selection.Insert Shift:=xlDown
    Range("C5").Select
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "0"
    Range("C5").Select
    Selection.AutoFill Destination:=Range("C5:H5"), Type:=xlFillDefault
    Range("C5:H5").Select
    Selection.AutoFill Destination:=Range("C5:H12"), Type:=xlFillDefault
    Range("C5:H12").Select
    Range("C110:H117").Select
    Selection.Delete Shift:=xlUp
End Sub
0
 
LVL 1

Author Comment

by:Lawrence Salvucci
ID: 39952992
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?
0
 
LVL 33

Expert Comment

by:Rob Henson
ID: 39953184
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.

Thanks
Rob H
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa‚Ķ

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question