Microsoft Office Tutorials and References

In Depth Information

**Figure 19-3. Worksheet to autofill range B1:B5**

Enum XlAutoFillType

xlFillDefault = 0

xlFillCopy = 1

xlFillSeries = 2

xlFillFormats = 3

xlFillValues = 4

xlFillDays = 5

xlFillWeekdays = 6

xlFillMonths = 7

xlFillYears = 8

xlLinearTrend = 9

xlGrowthTrend = 10

End Enum

If this argument is
xlFillDefault
or is omitted, Excel will attempt to select the most

appropriate fill type, based on the source data.

To illustrate, consider the code:

Range("A1:B1").AutoFill Range("A1:K1")

which autofills cells C1 through K1 using the source data in cells A1 and B1. If A1 contains 1 and

B1 contains 2, then this code will fill the destination cells with consecutive integers starting at 3

(in cell C1). Note that cells A1 and B1 are included in the destination range.

As another illustration, consider the worksheet in
Figure 19-3
,
where cell B1 contains the formula:

=A1*A1

Figure 19-3. Worksheet to autofill range B1:B5

The code:

Range("B1").AutoFill Range("B1:B5")

will produce the output shown in
Figure 19-4
.

Figure 19-4. Autofilling B1:B5 in
Figure 19-3