Name

range.AutoFill(Destination, [Type])

Synopsis

Automatically fills in the cells in a specified destination range based on the specified source range.

Argument

Settings

Destination

The cells to be filled, including the source range.

Type

The default value is xlFillDefault, which attempts to select the most appropriate fill type based on the source range. You can also explicitly specify the type using one of the following constants: xlFillDays, xlFillFormats, xlFillSeries, xlFillWeekdays, xlGrowthTrend, xlFillCopy, xlFillMonths, xlFillValues, xlFillYears, xlLinearTrend.

If the value of cell A1 is 1, the following code automatically fills in the remaining cells in the range A1:A5 with the values 2 through 5:

Dim srcRange As Range
Dim destRange As Range
 
Set srcRange = ActiveSheet.Range("A1")
Set destRange = ActiveSheet.Range("A1:A5")
srcRange.AutoFill destRange, xlFillSeries

Get Programming Excel with VBA and .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.