In this post, you’ll learn how you can autofill in your worksheet programmatically using Excel VBA.
How to Autofill in Your Worksheet using Excel VBA?
Here’s a below code snippet that demonstrates how you can do this. It takes the autofill data range from A1 and A2 and autofills the cells from A1 to A10.
Just enter the value 1 and 2 in cells A1 and A2 respectively and call this function to see the autofill in action.
Sub AutoFill() 'DP - VBA to demonstrate how to auto fill when you enter values in the cell A1 and A2. Dim InputSelection As Range Dim AutoFillRange As Range Set InputSelection = Sheet1.Range("A1:A2") Set AutoFillRange = Sheet1.Range("A1:A10") InputSelection.AutoFill Destination:=AutoFillRange End Sub