Repeating macro

elmalle

New Member
Joined
Aug 10, 2016
Messages
10
Hello everyone,

I am looking for a marcro that can copy and paste cells.

The value of cell X must be copied to a cell X + 6.
So A1 text "Xteam" has to be copied to cell A7, this up to cell A380.
The same applies to cell B2 + 6.

How can I do this,
I can not do it

thank you in advance
elmalle
 
Last edited:

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
In your example if we loop through column A, when I get to cell A7 which now contains the A1 value, I will paste that value from A7 (which originally came from A1) into A13. Is this what you are looking to do? Are all cells in Column A from 1 to 380 currently populated?

As to column B. Starting in B2 and only going down 5 rows to paste and do this to B380? Am I understanding your needs correctly?
 
Upvote 0
Assuming you start with values only in A1 and B2 this will fill down with the sequence you want.
Code:
Sub elmalle()
Const Nxt As Long = 7
Dim A As Variant, B As Variant, V As Variant, N As Long
A = Range("A1").Value
B = Range("B2").Value
ReDim V(Nxt To 380, 1 To 2)
For N = Nxt To 380
    If N Mod 6 = 1 Then
        V(N, 1) = A
        V(N + 1, 2) = B
    End If
Next N
Application.ScreenUpdating = False
Range("A" & Nxt, "B380").Value = V
Application.ScreenUpdating = True
End Sub
 
Upvote 0
I'll assume your thanks are directed to post #3 . Here's a modification that will allow you to set the max number of repeats of the A1:B2 content starting in row 7.
Code:
Sub elmalle2()
Const Nxt As Long = 7  '1st row to enter a repeat of A1:B2 contents
Const NumTimes As Long = 60  'number of times to repeat the A1:B2 contents
Dim A As Variant, B As Variant, V As Variant, N As Long
A = Range("A1").Value
B = Range("B2").Value
ReDim V(Nxt To (Nxt - 1) * NumTimes + 1 + Nxt, 1 To 2)
For N = Nxt To (Nxt - 1) * (NumTimes) + 1
    If N Mod 6 = 1 Then
        V(N, 1) = A
        V(N + 1, 2) = B
    End If
Next N
Application.ScreenUpdating = False
Range("A" & Nxt, Range("B" & (Nxt - 1) * NumTimes + 1 + Nxt)).Value = V
Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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