user3682157
user3682157

Reputation: 1695

VBA to Auto Fill Specific Number of Rows

I am trying to autofill a specific number of rows in a column based on a number found in another cell (which changes based on data)

So say cell D2 = 250

I need to label FF4:FF250 with numbers 1,2,3,4,5... so that it looks like this

       Column FF
Cell 4    1
Cell 5    2
Cell 6    3
Cell 7    4
 ...     ...

I'm playing around with something like this but it doesn't work

Sub AutoFillSpecific()

    MyValue = Range("D2").Value
    Range("FF4").Select
    Selection.AutoFill Destination:=Range(FF4:FFMyValue)  

Any help?

Upvotes: 1

Views: 10473

Answers (1)

Chrismas007
Chrismas007

Reputation: 6105

Assuming you have a value in FF4 to autofill down:

Range("FF4").Value = 1
Range("FF4").AutoFill Destination:=Range("FF4:FF" & MyValue), Type:=xlFillSeries

You'll want to add Dim MyValue As Long to avoid errors because it will make sure the value of D2 is a number when you move it into the MyValue.

Upvotes: 2

Related Questions