Programmatically automatically fill ranges with incrementally changing data
The AutoFill method of the 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:
The range that calls the AutoFill method, which specifies the starting point of the fill and contains an initial value.
The range that you want to fill, passed as a parameter to the AutoFill method. This destination range must include the range that contains the initial value.
Note
You cannot pass a NamedRange control in place of the Range. For more information, see Programmatic limitations of host items and host controls.
Example
private void AutoFill()
{
Excel.Range rng = this.Application.get_Range("B1");
rng.AutoFill(this.Application.get_Range("B1","B5"),
Excel.XlAutoFillType.xlFillWeekdays);
rng = this.Application.get_Range("C1");
rng.AutoFill(this.Application.get_Range("C1","C5"),
Excel.XlAutoFillType.xlFillMonths);
rng = this.Application.get_Range("D1","D2");
rng.AutoFill(this.Application.get_Range("D1","D5"),
Excel.XlAutoFillType.xlFillSeries);
}