Need help for VBA duplicate data.

motilulla

Well-known Member
Joined
Feb 13, 2008
Messages
2,362
Office Version
  1. 2010
Using Excel 2010

Hello,

Here below is a piece of code I have broken my head but cannot get it work the way I want.

I have some set of data in the range A2:C6 which I want to duplicate them in the row 20, 25, 30 and 35… code is working only for row 20 plese need help how can it be set for next to 25, 30, and for 35 row

VBA Code:
Sub DuplicateData()
 
  For i = 2 To 5 Step 1
    Cells(i, 1).Resize(2, 3).Copy
 
    Cells(20, 1).PasteSpecial xlValues 'code write only in row 20 i want to next data to write in row 25,30 and 35
 
  Next
  Application.CutCopyMode = False
 
End Sub
Thank you.

Regards,
Moti
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Try this:
VBA Code:
Sub DuplicateData()
      
  Dim i As Long
 
  Range("A2:C6").Copy
  
  For i = 20 To 35 Step 5
    Cells(i, 1).PasteSpecial xlValues 'code write only in row 20 i want to next data to write in row 25,30 and 35
  Next
  
  Application.CutCopyMode = False
 
End Sub
 
Upvote 0
Try this:
VBA Code:
Sub DuplicateData()
     
  Dim i As Long
 
  Range("A2:C6").Copy
 
  For i = 20 To 35 Step 5
    Cells(i, 1).PasteSpecial xlValues 'code write only in row 20 i want to next data to write in row 25,30 and 35
  Next
 
  Application.CutCopyMode = False
 
End Sub
Hello Joe4, I tried the code my code was duplicating step 2 results in the row 20 & 21 but next step 2 were going in to same 20 & 21 row I need my code work as below example.

Excel Question.xls
ABCD
1n1n2n3
211227
352232
491319
5121537
661125
7
8
9
10
11
12
13
14
15
16
17
18
19
2011227
2152232
22
23
24
2552232
2691319
27
28
29
3091319
31121537
32
33
34
35121537
3661125
37
38
Sheet2


Thank you.

Regards,
Moti
 
Upvote 0
Yes, you had a discrepancy in your original post. You said:
I have some set of data in the range A2:C6 which I want to duplicate them in the row 20, 25, 30 and 35
but it looks like you really meant C3, not C6.

That is a simple change:
Rich (BB code):
Sub DuplicateData()
    
  Dim i As Long
 
  Range("A2:C3").Copy
 
  For i = 20 To 35 Step 5
    Cells(i, 1).PasteSpecial xlValues 'code write only in row 20 i want to next data to write in row 25,30 and 35
  Next
 
  Application.CutCopyMode = False
 
End Sub
 
Upvote 0
Yes, you had a discrepancy in your original post. You said:

but it looks like you really meant C3, not C6.

That is a simple change:
Rich (BB code):
Sub DuplicateData()
  
  Dim i As Long
 
  Range("A2:C3").Copy
 
  For i = 20 To 35 Step 5
    Cells(i, 1).PasteSpecial xlValues 'code write only in row 20 i want to next data to write in row 25,30 and 35
  Next
 
  Application.CutCopyMode = False
 
End Sub
Hello Joe4, it is duplicating only row results cells “A2:C3” (4 times in the rows below.)

Please check my example sheet

I want the Cells “A2:C3” must go in to A20:C21,

And next Cells “A3:C4” must go in Cells A25:C26,

And next Cells “A4:C5” must go in Cells A30:C31,

And next Cells “A5:C6” must go in Cells A35:C36.

Thank you.

Regards,
Moti
 
Upvote 0
Oh, sorry I misunderstood.
I think you only need your past line updated from your original code:
VBA Code:
Sub DuplicateData()
      
  Dim i As Long
 
  For i = 2 To 5
    Cells(i, 1).Resize(2, 3).Copy
    Cells((i * 5) + 10, 1).PasteSpecial xlValues 'code write only in row 20 i want to next data to write in row 25,30 and 35
  Next
  
  Application.CutCopyMode = False
 
End Sub
 
Upvote 1
Solution
Oh, sorry I misunderstood.
I think you only need your past line updated from your original code:
VBA Code:
Sub DuplicateData()
     
  Dim i As Long
 
  For i = 2 To 5
    Cells(i, 1).Resize(2, 3).Copy
    Cells((i * 5) + 10, 1).PasteSpecial xlValues 'code write only in row 20 i want to next data to write in row 25,30 and 35
  Next
 
  Application.CutCopyMode = False
 
End Sub

Hello Joe4, great this did the trick worked as I required thank you for your kind help for solving my issue.

Have a good day and Good Luck,

Kind Regards,
Moti :)
 
Upvote 0
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,215,133
Messages
6,123,234
Members
449,092
Latest member
SCleaveland

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