EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home VBA VBA Resources VBA Tips VBA AutoFill
 

VBA AutoFill

Ashwani Jaiswal
Article byAshwani Jaiswal
Madhuri Thakur
Reviewed byMadhuri Thakur

VBA AutoFill

VBA AutoFill in Excel

Sometimes in excel when we work on similar kind of data set which keeps on repeating, excel itself suggests sequential values as AutoFill. This is quite easy to implement and use. As mostly we get a sequence of autofill in the form of Numbers, Weekdays, Months or any number series. If we create autofill or not but excel sometimes create the Autofill to accompany in completing the task quickly.

 

 

How to Use VBA AutoFill Function in Excel?

We will learn how to use a VBA Autofill function with few examples in excel.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

You can download this VBA AutoFill Excel Template here – VBA AutoFill Excel Template

Example #1 – VBA AutoFill

Let’s see an example where we will autofill months names in a proper sequence. In column A we have name of 2 months Jan and Fed in short. And we will write a code which will fill rest of the months automatically till Dec.

VBA Example 1

Follow the below steps to use VBA AutoFill function in Excel:

Step 1: For this, we need a module. Go to Insert menu and select the module as shown below.

AutoFill Module 1

Step 2: After we get a module, in that write subcategory of VBA Autofill or in any other name of your choice as shown below.

Code:

Sub VBA_Autofill()

End Sub

VBA Example 1.1

Step 3: Select the range of the cells which we need to drag or extent for autofill. We have cell A1 and A2.

Code:

Sub VBA_Autofill()

Range ("A1:A2")

End Sub

Excel VBA Autofill Example 1.2

Step 4: Now select the function we need to perform which is “Autofill”, allowing the Destination to get selected as shown below.

Code:

Sub VBA_Autofill()

Range("A1:A2").AutoFill Destination:=

End Sub

VBA Example 1.3

Step 5: Now select the range where we will need to autofill the names of months till Dec. We can select any range but selecting the same range makes it easy to implement.

Code:

Sub VBA_Autofill()

Range("A1:A2").AutoFill Destination:=Range("A1:A12")

End Sub

VBA Example 1.4

Step 6: Now here comes the moment, when we will select the time of autofill we need. Select the Type as xlFillMonths as shown below.

Code:

Sub VBA_Autofill()

Range("A1:A2").AutoFill Destination:=Range("A1:A12"), Type:=xlFillMonths

End Sub

VBA Example 1.5

Step 7: Once done, compile the code and run it by clicking on the Play button which is located below the menu bar in VBA or Press F5. And we will see, in a moment list of months from Jan to Dec will get automatically filled from cell A3 to A12.

VBA 1.6

Example #2 – VBA AutoFill

In this example we will see, how to Autofill numbers. We have column B with some numbers from 1 to 4 as shown below. Now we will Autofill the numbers till 10 automatically.

VBA Eample 2

Step 1: For this we need a module where will implement the code for AutoFill the numbers. Open a module and create a sub category in the name of VBA AutoFill as shown below.

Code:

Sub VBA_Autofill2()

End Sub

VBA Example 2.1

Step 2: Now select the range of the cells which are currently available which is from B1 to B4.

Code:

Sub VBA_Autofill2()

Range("B1:B4").

End Sub

VBA Example 2.2

Step 3: Select the AutoFill function followed by the Destination command as shown below.

Code:

Sub VBA_Autofill2()

Range("B1:B4").AutoFill Destination:

End Sub

VBA Example 2.3

Step 4: Now select the range of the cells till we want to autofill the numbers. Here we are making it till number 10. So, select the range from cell B1 to B10.

Code:

Sub VBA_Autofill2()

Range("B1:B4").AutoFill Destination:=Range("B1:B10"),

End Sub

VBA Example 2.4

Step 5: Now for Auto filling numbers, we will select Type as xlFillDefault is meant only for number kind of things.

Code:

Sub VBA_Autofill2()

Range("B1:B4").AutoFill Destination:=Range("B1:B10"), Type:=xlFillDefault

End Sub

VBA Example 2.5

Step 6: Now compile the code and run to get the output. We will see numbers are auto filled from 1 to 10 as shown below.

Excel VBA EXAMPLE 2

Example #3 – VBA AutoFill

There is another way to autofill the content of any columns. This can be done for anything. Numbers, Text or any combination. We have considered the numbers here in Column C from 1 to 4 as shown below.

VBA Example 3

Step 1: Open a module, in that create the subcategory of VBA Autofill shown below.

Code:

Sub VBA_Autofill3()

End Sub

VBA SUB 3.1

Step 2: As the same above examples, we will select the range of the cells which has the data and need to get Autofill.

Code:

Sub VBA_Autofill3()

Range("C1:C4").

End Sub

VBA Range

Step 3: In the same manner as shown in the above examples, select the Autofill function followed by Destination command.

Code:

Sub VBA_Autofill3()

Range("C1:C4").AutoFill Destination:=

End Sub

Autofill Destination

Step 4: Select the range of cells till where we need to autofill the cell contents. Here we are selecting the range of cell C1 to C12.

Code:

Sub VBA_Autofill3()

Range("C1:C4").AutoFill Destination:=Range("C1:C12"),

End Sub

Destination RANGE 2

Step 5: Now select the Type of autofill we want. Here we are selecting xlFillCopy which will Copy and Paste the data available in selected range cells to destination cells.

Code:

Sub VBA_Autofill3()

Range("C1:C4").AutoFill Destination:=Range("C1:C12"), Type:=xlFillCopy

End Sub

RANGE 2

Step 6: At last, compile the code in one go, as it is a single line code and run. We will numbers from 1 to 4 are now copied to the cell till cell C12. And we can see all 4 numbers are copied twice.

Excel VBA AutoFILL 3

Example #4 – VBA AutoFill

In this example we will see how to AutoFill format of cells to below destination cells. Format can be Bold, Italic or colored cells. Here we have columns D with some colored cells D1 to D3 as shown below.

EXAMPLE 4.1

Step 1: Open a new module and create a sub category of VBA AutoFill or in any other name. As we can see, here we have kept all the sub categories in numerical sequence.

Code:

Sub VBA_Autofill4()

End Sub

Excel VBA Autofill Example 4.2

Step 2: Select a range of those cells which has a colored background. Here those cells range is D1 to D3.

Code:

Sub VBA_Autofill4()

Range("D1:D3").

End Sub

Excel Example 4.3

Step 3: Now select AutoFill function with command Destination as shown below.

Code:

Sub VBA_Autofill4()

Range("D1:D3").AutoFill Destination:=

End Sub

Example 4.4

Step 4: Now select the Destination range of cells where we need to autofill the format cells. Here we are selecting D1 to D10.

Code:

Sub VBA_Autofill4()

Range("D1:D3").AutoFill Destination:=Range("D1:D10"),

End Sub

Example 4.5

Step 5: At last select the Type which we need to autofill in destination cells as xlFillFormat.

Code:

Sub VBA_Autofill4()

Range("D1:D3").AutoFill Destination:=Range("D1:D10"), Type:=xlFillFormat

End Sub

Excel VBA Example 4.6

Step 6: Finally we can compile the code and run it. We will the color which are in cells D1 to D3 are auto filled to the cell till D10.

example 4.7

Pros of VBA AutoFill

  • It saves the time by automatically filling the content of the cells which need to be filled repeatedly.
  • Sequential data can be automatically filled to save file.

Things to Remember

  • Autofill can be used for formatting, copying, dragging for numbers and text.
  • If possible then keep the proper sequence of code while writing multiple codes.
  • It is always better to automate the data which we need to fill in same manner.
  • New version of MS Excel has function where if we enter one data set one time then next time we just need to fill 2-3 cells and it will automatically suggest to fill the entire range.

Recommended Articles

This is a guide to VBA Autofill. Here we discuss how to use Excel VBA Autofill Function along with practical examples and downloadable excel template. You can also go through our other suggested articles –

  1. Copy Paste Function in VBA
  2. Substring Excel Function
  3. VBA Subscript out of Range
  4. Excel ISNUMBER Formula

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Web Development & many more.

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA

Download VBA AutoFill Excel Template

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW