0

I am currently working on a excel-VBA macro that would selected a template, copy it, create extra rows above the selected cell and afterwards paste the template into the added extra rows. So far my code looks like this:

Sub Insert_Another_Good()
    Dim i As Integer
    Dim j As Integer
    ActiveCell.EntireRow.Select
    i = 8
    For j = 1 To i
        Selection.Insert Shift:=xlToDown, CopyOrigin:=xlFormatFromRightorAbove
    Next: Macro2
    Range("A25:P32").Copy
    Set rng = Range(Selection.Address)
    ActiveSheet.Paste
End Sub

Sub Macro2() 'still part of the same sub'
    Range("A25:P32").Copy
    Set rng = Range(Selection.Address)
    ActiveSheet.Paste
End Sub

This works well for copying the template and pasting it into the new lines but it only pastes starting from the very first, A, column. Could you please help me make it so it pastes the template in lets say column Q? (Bus still the same row as the first line out of new 8 posted)

Hope you understood my weird question ! And thanks for help in advance!

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
  • Welcome to Stack Overflow! Please take a moment and check out the [tour] as well as [ask] and [mcve]. Have you tried Googling "copy and paste with excel vba"? – ashleedawg Nov 28 '17 at 14:26
  • It may be because of your use of `Selection`. You should always try and [avoid using `.Activate``/`.Select`](https://stackoverflow.com/questions/10714251/) – BruceWayne Nov 28 '17 at 15:03

1 Answers1

0

How about instead of inserting empty rows you simply insert the copied range and shift everything down, like so:

Range("A25:P32").Copy
Set Rng = Range(Selection.Address)
Selection.Insert Shift:=xlDown
Xabier
  • 7,587
  • 1
  • 8
  • 20