Copy & paste cell x times (x = value of another cell)

Bungraman

Board Regular
Joined
May 26, 2010
Messages
126
Hi all
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
Another problem and which I can’t find a solution anywhere. I have the following code:

Code:
Sub CopyData()
Dim MyRange As Range
Dim i As Long
Dim r As Range
    Set r = Range("C1001")
    Set MyRange = Range("B1000")
Application.ScreenUpdating = False
 
        Range("C1001").Select
        ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-1],R5C1:R999C3,3)"
 
    For i = 1 To MyRange
 
        r.Copy
        'Set MyRange = MyRange.Offset(1, 0)
        'Selection.Offset(1, 0).Select
        Set r = r.Offset(r.Rows.Count)
        ActiveSheet.Paste r
    Next i
Application.ScreenUpdating = True
End Sub
<o:p></o:p>
Cells in Column “C1001” onwards are empty. I want to put the lookup formula in this cell C1001 and copy it to the next cell down by the number of times based on the value in cell B1000. It runs but it pastes an extra formula than the amount required. For example, if B1000 = 10, only cells C1001 to C1011 should be populated with the formula, but C1012 has the formula too.
<o:p></o:p>
I must be missing something in my code.
<o:p></o:p>
Can anybody help please??
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Try this...

Code:
[color=darkblue]Sub[/color] CopyData()
 
    Range("C1001").Resize(Range("B1000").Value).FormulaR1C1 = "=VLOOKUP(RC[-1],R5C1:R999C3,3)"
 
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Upvote 0

Forum statistics

Threads
1,225,156
Messages
6,183,246
Members
453,152
Latest member
ChrisMd

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