Copy range and paste to every nth column

rjh3m8

New Member
Joined
Jan 27, 2022
Messages
20
Office Version
  1. 365
  2. 2021
Platform
  1. MacOS
Hi, I am trying to copy a range of data and paste it to every 4th column. For instance, Row 1 has 25 columns of datapoints, I want each datapoint to be 4 columns apart. Then again for Row 2 data... Row 3 data... on and so forth. I have the following code I edited from somewhere else, but it is pasting only one row of data to one column, with each data point spaced 4 rows apart. Can anyone help me see where it's gone wrong?

Sub Copy_Paste_nth()
Dim i As Long, r As Long
Dim Rng As Range

With Sheets("Sheet1")
Set Rng = .Range("A1:Y1", .Range("A" & Rows.Count).End(xlUp))
End With
For i = 2 To Rng.Count * 4 Step 4
r = r + 1
Sheets("Sheet2").Range("C" & i).Value = Rng(r).Value
Next i
End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
If I correctly understood your request try this instead:
VBA Code:
Option Explicit
Sub Copy_Paste_nth()
    Dim i As Long, r As Long
    With Sheets("Sheet1")
        For i = 2 To .Range("A" & Rows.Count).End(xlUp).Row
            r = r + 4
            .Range("A" & i & ":Y" & i).Copy Sheets("Sheet2").Range("C" & r)
        Next i
    End With
End Sub
 
Upvote 0
My take on this
VBA Code:
Sub rjh3m()
   Dim i As Long, UsdRws As Long
   
   With Sheets("Sheet1")
      UsdRws = .Range("A" & Rows.Count).End(xlUp).Row
      For i = 1 To .Cells(1, Columns.Count).End(xlToLeft).Column
         Sheets("Sheet2").Cells(1, i * 4 - 3).Resize(UsdRws).Value = .Cells(1, i).Resize(UsdRws).Value
      Next i
   End With
End Sub
 
Upvote 0
My take on this
VBA Code:
Sub rjh3m()
   Dim i As Long, UsdRws As Long
  
   With Sheets("Sheet1")
      UsdRws = .Range("A" & Rows.Count).End(xlUp).Row
      For i = 1 To .Cells(1, Columns.Count).End(xlToLeft).Column
         Sheets("Sheet2").Cells(1, i * 4 - 3).Resize(UsdRws).Value = .Cells(1, i).Resize(UsdRws).Value
      Next i
   End With
End Sub
This worked really well! In fact, a little too well, as it captured all the data on the first sheet and spaced it out evenly on the second sheet. Can you indicate where I would adjust this to copy only a specific range?
 
Upvote 0
Which range do you want to copy?
 
Upvote 0
Which range do you want to copy?
At first, DY2:EW2 to last row
But then I'll need a different set of cells copied and pasted the same way for another iteration elsewhere
 
Upvote 0
Ok, how about
VBA Code:
Sub rjh3m()
   Dim i As Long, UsdRws As Long
   
   With Sheets("Sheet1")
      UsdRws = .Range("A" & Rows.Count).End(xlUp).Row
      For i = 1 To Range("DY2:EW2").Columns.Count
         Sheets("Sheet2").Cells(1, i * 4 - 3).Resize(UsdRws).Value = .Cells(1, i).Resize(UsdRws).Value
      Next i
   End With
End Sub
 
Upvote 0
Ok, how about
VBA Code:
Sub rjh3m()
   Dim i As Long, UsdRws As Long
  
   With Sheets("Sheet1")
      UsdRws = .Range("A" & Rows.Count).End(xlUp).Row
      For i = 1 To Range("DY2:EW2").Columns.Count
         Sheets("Sheet2").Cells(1, i * 4 - 3).Resize(UsdRws).Value = .Cells(1, i).Resize(UsdRws).Value
      Next i
   End With
End Sub
I think we're close! This iteration selected the correct number of columns (25 total) but it still started at column A.
 
Upvote 0

Forum statistics

Threads
1,215,051
Messages
6,122,872
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