Copy range to every nth cell

Dokat

Active Member
Joined
Jan 19, 2015
Messages
304
Office Version
  1. 365
Hi,

I have a spreadsheet where i would like to copy values between "G20:R20" and paste to every 14th cell in the same row (20). I am using below code. its running but doesn't change the values and paste the copy range. Can anyone help me with below code?


VBA Code:
Sub CopyDateHeaders()
'Modified  7/3/2023  1:53:43 AM  EST
Application.ScreenUpdating = False

Dim cpy As range
Dim lastRow As Long

With Worksheets("Summary by 33")
    lastRow = 20
    Set cpy = .range("G20:R20")

    For colx = 20 To 188 Step 14
        .range(.Cells(20, colx), .Cells(lastRow, colx)).Value = cpy.Value
    Next
    
End With

Application.ScreenUpdating = True

End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Untested, but I am pretty sure this modified version of your macro should work...
VBA Code:
Sub CopyDateHeaders()
    'Modified  7/3/2023  1:53:43 AM  EST
    Application.ScreenUpdating = False
   
    Dim cpy As Range
    Dim lastRow As Long, N As Long
   
    With Worksheets("Summary by 33")
        lastRow = 20
        Set cpy = .Range("G20:R20")
   
        For colx = 20 To 188 Step 14
            .Cells(20, colx).Value = cpy.Offset(0, N).Value
            N = N + 1
        Next
       
    End With
   
    Application.ScreenUpdating = True

End Sub
NOTE: I left it in just in case you had plans for using it later on, but as written, your code does not need/use the lastRow variable.
 
Upvote 0
Untested, but I am pretty sure this modified version of your macro should work...
VBA Code:
Sub CopyDateHeaders()
    'Modified  7/3/2023  1:53:43 AM  EST
    Application.ScreenUpdating = False
 
    Dim cpy As Range
    Dim lastRow As Long, N As Long
 
    With Worksheets("Summary by 33")
        lastRow = 20
        Set cpy = .Range("G20:R20")
 
        For colx = 20 To 188 Step 14
            .Cells(20, colx).Value = cpy.Offset(0, N).Value
            N = N + 1
        Next
     
    End With
 
    Application.ScreenUpdating = True

End Sub
NOTE: I left it in just in case you had plans for using it later on, but as written, your code does not need/use the lastRow variaThanks for your response. Whe

Untested, but I am pretty sure this modified version of your macro should work...
VBA Code:
Sub CopyDateHeaders()
    'Modified  7/3/2023  1:53:43 AM  EST
    Application.ScreenUpdating = False
  
    Dim cpy As Range
    Dim lastRow As Long, N As Long
  
    With Worksheets("Summary by 33")
        lastRow = 20
        Set cpy = .Range("G20:R20")
  
        For colx = 20 To 188 Step 14
            .Cells(20, colx).Value = cpy.Offset(0, N).Value
            N = N + 1
        Next
      
    End With
  
    Application.ScreenUpdating = True

End Sub
NOTE: I left it in just in case you had plans for using it later on, but as written, your code does not need/use the lastRow variable.
Thank you for your quick response. However when i ran the code it didnt copy paste the range (G20:R20) and didnt give any error message. I removed lastrow variable.
 
Upvote 0
Sorry, my fault. Try changing this line of code...

.Cells(20, colx).Value = cpy.Offset(0, N).Value

to this...

.Cells(20, colx).Value = cpy(1).Offset(0, N).Value
 
Upvote 0
Sorry, my fault. Try changing this line of code...

.Cells(20, colx).Value = cpy.Offset(0, N).Value

to this...

.Cells(20, colx).Value = cpy(1).Offset(0, N).Value
Thank you, it still only copied value in R20 to T20, no other changes.
 
Upvote 0
If I understand your setup correctly, I do not see how that is possible. Can you post a desensitized copy of your workbook to DropBox so I can see how the code runs against your actual data?
 
Upvote 0
If I understand your setup correctly, I do not see how that is possible. Can you post a desensitized copy of your workbook to DropBox so I can see how the code runs against your actual data?
Thank you. here is the dropbox link.


I am trying to copy values between "G20:R20" to every 14th cell. Next paste would be starting cell "T20:AE20". Hope this clarifies.
 
Upvote 0
Just so I understand your request correctly, what cells should G20 and H20 (I'll figure out the rest from there) be placed in?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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