We recommend using Visual Studio 2017

How to: Programmatically Automatically Fill Ranges with Incrementally Changing Data


The AutoFill method of the Microsoft.Office.Interop.Excel.Range object enables you to fill a range in a worksheet with values automatically. Most often, the AutoFill method is used to store incrementally increasing or decreasing values in a range. You can specify the behavior by supplying an optional constant from the XlAutoFillType enumeration.

Applies to: The information in this topic applies to document-level projects and VSTO add-in projects for Excel. For more information, see Features Available by Office Application and Project Type.

You must specify two ranges when using AutoFill:

        private void AutoFill()
            Excel.Range rng = this.Application.get_Range("B1");

            rng = this.Application.get_Range("C1"); 

            rng = this.Application.get_Range("D1","D2");

The first cell of the range that you want to fill must contain an initial value.

The example requires that you fill three regions:

  • Column B is to include five weekdays. For the initial value, type Monday in cell B1.

  • Column C is to include five months. For the initial value, type January in cell C1.

  • Column D is to include a series of numbers, incrementing by two for each row. For the initial values, type 4 in cell D1 and 6 in cell D2.

Working with Ranges
How to: Programmatically Refer to Worksheet Ranges in Code
How to: Programmatically Apply Styles to Ranges in Workbooks
How to: Programmatically Run Excel Calculations Programmatically
Host Items and Host Controls Overview
Optional Parameters in Office Solutions