How to Autofill in Your Worksheet using Excel VBA?

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
How to Autofill in Your Worksheet using Excel VBA?

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

In this post, you’ll learn how to Find Blank cells in excel so that you can remove or delete the blank cells form...
In this article, you’ll learn what is a Gauge Chart in Microsoft Excel. Also, you will learn how to add...
Microsoft Excel provides a shortcut for the users to move columns in excel using two different ways – using Shift...