📊 Excel VBA Top100

AutoFillSeries

自動化

選択セルの値を起点に連続データを下方向に自動入力します

🎬 デモGIF準備中

📖 使い方

  1. VBAエディタを開く(Alt + F11)
  2. モジュールを挿入(挿入 > モジュール)
  3. 下記VBAコードをコピー&ペースト
  4. ブック上で実行(Alt + F8 でマクロ選択)
💡 実行例: 起点となるセルを選択してから AutoFillSeries を実行します

💻 VBAコード

' AutoFillSeries
' -----------------
' Macro Name: AutoFillSeries
' Description: 選択セルの値を起点に連続データを下方向に自動入力します
' Parameters: なし
' Returns: なし
' Usage: 起点となるセルを選択してから AutoFillSeries を実行します
' -----------------

Sub AutoFillSeries()
    On Error GoTo ErrorHandler

    Dim startCell As Range
    Dim countStr As String
    Dim fillCount As Long
    Dim fillRange As Range

    If TypeName(Selection) <> "Range" Then
        MsgBox "起点セルを選択してから実行してください", vbCritical, "エラー"
        Exit Sub
    End If

    Set startCell = Selection.Cells(1, 1)

    countStr = InputBox("入力する件数を入力してください", "件数", "10")
    If countStr = "" Then Exit Sub
    If Not IsNumeric(countStr) Then
        MsgBox "数値を入力してください", vbCritical, "エラー"
        Exit Sub
    End If

    fillCount = CLng(countStr)
    Set fillRange = startCell.Resize(fillCount, 1)
    startCell.AutoFill Destination:=fillRange, Type:=xlFillSeries

    MsgBox fillCount & " 件の連続データを入力しました", vbInformation, "完了"

    Exit Sub

ErrorHandler:
    MsgBox "エラーが発生しました:" & vbCrLf & Err.Description, vbCritical, "エラー"
End Sub