Reputation: 35
I'm attempting to use VBA to automate filling cells with formulas, I have managed to pull my formulas in the cells properly, although I seem to be unable to either figure the proper way to use .range or maybe this isn't possible.
Is there a way that I can select an area that I'd like to fill down? I know that you can manually do this by selecting a set of cells and then filling down an area.
I was able to make something work by using an incredibly inefficient loop, but I know there's a better way to do this.
The code that I would have thought would make this work is
Worksheets("sheet1").range("K1:K4", "K5:K" & lastrow).filldown
but this doesn't do anything but repeat the data in K1 down.
Upvotes: 0
Views: 180
Reputation: 6664
You can use the AutoFill
Property of Range to drag the Formulas Down.
Code:
Sub fill()
LastRow = 19
With Worksheets("sheet1")
.Range("K1:K4").AutoFill Destination:=Range("K1:K" & LastRow), Type:=xlFillDefault
End With
End Sub
Working:
Upvotes: 1