VBA Macro Code for Copy&Paste using iterative loops

MacroNew

New Member
Joined
Nov 11, 2021
Messages
2
Office Version
  1. 2007
Platform
  1. Windows
Hello everyone I hope everything is good with you.
I'm newbie at VBA coding and I'm looking for a little help on my code here.
The idea is simple I have 2 Worksheets ("Input" and "template") I need to copy values from range A of Worksheet "Input" and paste it in "template" cells, however in "template", the cells starts in A3 and next is A7, A11 and so on until 39.
For instance:
Input:A1 = template:A3,
Input:A2 = template:A7,
Input:A3 = template:A11...
I'm pasting my code here, but I'm not sure how to add this second loop for template sheet, I've tried to use a for and increment it by 4 but it didn't work.
Any help will appreciated.

Sub CopyPaste()

' CopyPaste Test Macro
'
' Keyboard Shortcut: Ctrl+x
'
Dim rng As Range
Dim i As Integer

For Each Cl In Sheets("Input").Range("A1", Range("A" & Rows.Count).End(xlUp))
For i = 3 To 39
If Cl.Value <> "" Then
Sheets("template").Range("A" & i).Value = Cl.Value
i = i + 4

Next Cl

End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
14,343
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
Maybe...

VBA Code:
Sub CopyPaste()

    ' CopyPaste Test Macro
    '
    ' Keyboard Shortcut: Ctrl+x
    '
    Dim Cl As Range
    Dim i As Integer
    i = 3
    For Each Cl In Sheets("Input").Range("A1", Sheets("Input").Range("A" & Rows.Count).End(xlUp))
        'For i = 3 To 39
        If Cl.Value <> "" Then
            Sheets("template").Range("A" & i).Value = Cl.Value
            i = i + 4
            If i > 39 Then Exit Sub
        End If
    Next Cl

End Sub
 

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
14,343
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
Happy it helped and welcome to the forum 🙂
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,044
Messages
5,767,800
Members
425,437
Latest member
blaix

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
Top