●次に、AutoFillの定数の種類を説明します。下記に一覧表を作成しましたので、参照してください。
定数 | 説明 |
---|---|
xlFillDefault | 標準のオートフィル(既定値) |
xlFillCopy | コピー(値・書式) |
xlFillSeries | 連続データ |
xlFillFormats | 書式のみコピー |
xlFillValues | 書式なしのコピー |
xlFillDays | 日単位の連続データ |
xlFillWeekdays | 土日を除く平日 |
xlFillMonths | 月単位の連続データ |
xlFillYears | 年単位の連続データ |
xlLinearTrend | 連続データ(加算) |
xlGrowthTrend | 連続データ(乗算) |
Sub AutoFill() '標準のオートフィル(既定値) Range("A1").AutoFill Destination:=Range("A1:A10"), Type:=xlFillDefault 'コピー(値・書式) Range("B1").AutoFill Destination:=Range("B1:B10"), Type:=xlFillCopy '連続データ Range("C1").AutoFill Destination:=Range("C1:C10"), Type:=xlFillSeries '書式のみコピー Range("D1").AutoFill Destination:=Range("D1:D10"), Type:=xlFillFormats '書式なしのコピー Range("E1").AutoFill Destination:=Range("E1:E10"), Type:=xlFillValues '日単位の連続データ Range("F1").AutoFill Destination:=Range("F1:F10"), Type:=xlFillDays '土日を除く平日 Range("G1").AutoFill Destination:=Range("G1:G10"), Type:=xlFillWeekdays '月単位の連続データ Range("H1").AutoFill Destination:=Range("H1:H10"), Type:=xlFillMonths '年単位の連続データ Range("I1").AutoFill Destination:=Range("I1:I10"), Type:=xlFillYears '連続データ(加算) Range("J1").AutoFill Destination:=Range("J1:J10"), Type:=xlLinearTrend '連続データ(乗算) Range("K1:k2").AutoFill Destination:=Range("K1:K10"), Type:=xlGrowthTrend End Sub
Sub AutoFill_table() Dim I As Long Dim Hani As Range Range("A3") = "月曜日" Range("B2") = "4月" Range("A10,N2") = "合計" Range("B10") = "=SUM(B3:B9)" Range("N3") = "=SUM(B3:M3)" Range("A3").AutoFill Destination:=Range("A3:A9"), Type:=xlFillSeries '曜日を連続データ表示 Range("B2").AutoFill Destination:=Range("B2:M2"), Type:=xlFillMonths '月単位の連続データ Range("B10").AutoFill Destination:=Range("B10:N10"), Type:=xlFillDefault '横合計複写(SUM) Range("N3").AutoFill Destination:=Range("N3:N9"), Type:=xlFillDefault '縦合計複写(SUM) 'サンプルデータ作成 For Each Hani In Range("B3:M9") 'サンプルデータの範囲 I = I + 1 Hani = I Next Hani '罫線作成 Range("A2:N10").Borders.LineStyle = xlContinuous '囲線 End Sub