Error: runtime error 1004 paste method of worksheet class

Ricardo4545

New Member
Joined
Apr 7, 2015
Messages
3
Hello all, I just got introduced to VBA and am trying my first steps in it.
I have data in 3 consecutive rows (let's say A1:E3) and every 3 rows of data, I want to move that "block" --> two cells to the right.
So basically, I have:
Code:
A1 B1 C1 D1 E1
A2 B2 C2 D2 E2
A3 B3 C3 D3 E3

That want to turn into

Code:
A1     B1     C1     D1     E1
A2     B2     C2     D2     E2
A3     B3     C3     D3     E3

Thing is, I need to start o the active cell and not specifically A1 pushing it specifically to A3.
I'm using this code:

Code:
Sub Macro1()
Do Until IsEmpty(ActiveCell.Offset(0, 1))

ActiveCell.Offset(0, 1).Select
ActiveCell.Resize(3, 1).Select
Range(Selection, Selection.End(xlToRight)).Cut
ActiveCell.Offset(0, 2).Select
ActiveSheet.Paste

Loop
End Sub

But i get the error: "runtime error 1004 method of worksheet class". Everything works just fine until the last "block" of data (E1:E3).
The line "ActiveSheet.Paste". Gets highlighted.
This may sound like an ultra naïve question, but I can't solve it.

Thanks in advance!
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Maybe this
Adjust the starting point to suit
Code:
Sub MM1()
For c = 2 To 10 Step 2 ' the 2 is the starting column
Columns(c).Insert
Next
End Sub
 
Upvote 0
This should solve your error

Code:
Sub Macro1()
   Do Until IsEmpty(ActiveCell.Offset(0, 1))

      ActiveCell.Offset(0, 1).Select
      ActiveCell.Resize(3, 1).Select
      Range(Selection, Selection.End(xlToRight)).Cut ActiveCell.Offset(0, 2)
   Loop
End Sub
 
Upvote 0
Maybe this
Adjust the starting point to suit
Code:
Sub MM1()
For c = 2 To 10 Step 2 ' the 2 is the starting column
Columns(c).Insert
Next
End Sub


Hi Michael!
Thanks a million first of all for the reply :)
I tried your code but it inserts columns between the data. I only wanted to insert blank cells between the presented data as I have some more information above that didn't want to be split.
 
Upvote 0
Hi sericom!
Thanks for your reply.
The code you provided inserts blank cells only between the frist and second "blocks". So what it makes is:
Code:
A1        B1 C1 D1 E1 
A2        B2 C2 D2 E2
A3        B3 C3 D3 E3
 
Upvote 0
Maybe this....but I'm not sure using seletcion is the way to go, as it could cause lots of errors
You need to ensure the left / top is selected for it to work correctly...no a good method !
You also need to adjust the line higlighted to suit the number of columns
Code:
Sub MM1()
For x = 1 To 3 ' 3 will do a block of 3 units
      Range(ActiveCell.Offset(0, x), ActiveCell.Offset(2, x)).Select
      Selection.Insert
Next x
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,744
Messages
6,126,621
Members
449,322
Latest member
Ricardo Souza

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