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

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
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
 
Upvote 0
Happy it helped and welcome to the forum ?
 
Upvote 0

Forum statistics

Threads
1,214,823
Messages
6,121,779
Members
449,049
Latest member
greyangel23

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