VBA Code to copy multiple rows from one sheet and insert them below activecell in another sheet

aitorsol

New Member
Joined
Apr 7, 2019
Messages
2
Hi
I have an error -2147417848 of Automation on line 70 when i use this macro, sometimes the first execution, and always the second:


Public Sub InsertCopiedCells()
10 On Error GoTo InsertCopiedCells_Error
'IT IS NECESSARY TO CALL THIS MACRO FROM THE SHEET "TARGET"
'WITH A ROW SELECTED AND IS WHERE BELOW THIS ROW WILL BE
'INSERTED THE ROWS 55 TO 67 COPIED FROM THE SHEET "ORIGIN"
Dim a As Integer
20 Sheets("ORIGIN").Select
30 Rows("55:67").Select
40 Selection.Copy
50 Sheets("TARGET").Select
60 ActiveCell.Offset(1, 0).Rows("1:1").EntireRow.Select
70 Selection.Insert Shift:=xlDown
80 Application.CutCopyMode = False
90 On Error GoTo 0
100 Exit Sub
InsertCopiedCells_Error:
110 MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure InsertCopiedCells, line " & Erl & "."
End Sub


 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Hi
I have an error -2147417848 of Automation on line 70 when i use this macro, sometimes the first execution, and always the second:


Public Sub InsertCopiedCells()
10 On Error GoTo InsertCopiedCells_Error
'IT IS NECESSARY TO CALL THIS MACRO FROM THE SHEET "TARGET"
'WITH A ROW SELECTED AND IS WHERE BELOW THIS ROW WILL BE
'INSERTED THE ROWS 55 TO 67 COPIED FROM THE SHEET "ORIGIN"
Dim a As Integer
20 Sheets("ORIGIN").Select
30 Rows("55:67").Select
40 Selection.Copy
50 Sheets("TARGET").Select
60 ActiveCell.Offset(1, 0).Rows("1:1").EntireRow.Select
70 Selection.Insert Shift:=xlDown

80 Application.CutCopyMode = False
90 On Error GoTo 0
100 Exit Sub
InsertCopiedCells_Error:
110 MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure InsertCopiedCells, line " & Erl & "."
End Sub



Try replacing the highlighted code with:
Code:
20 Sheets("ORIGIN").Rows("55:67").Copy
50 Sheets("TARGET").Select
60 ActiveCell.Offset(1, 0).Insert Shift:=xlDown
 
Upvote 0

Forum statistics

Threads
1,223,900
Messages
6,175,276
Members
452,629
Latest member
SahilPolekar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top