Copy Paste VBA

timjohnny

New Member
Joined
Aug 23, 2021
Messages
17
Office Version
  1. 2019
Platform
  1. Windows
hi all, I hope you're all well :

I'm trying my luck with writing a Macro today for the first time and would be super grateful for a little help. I'm trying to copy three cells from one row over into another sheet, across three columns. Then I'd like to move on to the next row and copy over across the adjacent three columns. This is what I've written so far:

Sub first_macro()
Worksheets("Rewards Structure").Range("A2:C2").Copy Worksheets("Index").Range("E4:g4")
Worksheets("Rewards Structure").Range("A3:C3").Copy Worksheets("Index").Range("h4:j4")
Worksheets("Rewards Structure").Range("A4:C4").Copy Worksheets("Index").Range("k4:m4")
Worksheets("Rewards Structure").Range("A5:C5").Copy Worksheets("Index").Range("n4:p4")
Worksheets("Rewards Structure").Range("A6:C6").Copy Worksheets("Index").Range("q4:s4")
End Sub

Now, I want to do this for 150 rows, so I could just write another 145 lines of code. But I wondered whether anyone knows a way to condense it?

Thanks a lot for any help!
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Hi & welcome to MrExcel.
How about
VBA Code:
Sub timjohnny()
   Dim i As Long
   
   With Sheets("Rewards Structure")
      For i = 2 To 151
         .Range("A" & i).Resize(, 3).Copy Sheets("Index").Cells(4, i * 3 - 1)
      Next i
   End With
End Sub
 
Upvote 0
Solution
oh you're the best thank you so so much! This is v exciting :) I'm starting a VBA course online this week so I'm v excited to become more active here :) Thanks again!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,893
Members
449,097
Latest member
dbomb1414

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