📊 Excel VBA Top100

TimestampCells

自動化

選択範囲のセルに現在の日時をタイムスタンプとして入力します

🎬 デモGIF準備中

📖 使い方

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

💻 VBAコード

' TimestampCells
' -----------------
' Macro Name: TimestampCells
' Description: 選択範囲のセルに現在の日時をタイムスタンプとして入力します
' Parameters: なし
' Returns: なし
' Usage: 対象セル範囲を選択してから TimestampCells を実行します
' -----------------

Sub TimestampCells()
    On Error GoTo ErrorHandler

    Dim rng As Range
    Dim cell As Range
    Dim now As Date

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

    Set rng = Selection
    now = Now

    For Each cell In rng
        cell.Value = now
        cell.NumberFormat = "yyyy/mm/dd hh:mm:ss"
    Next cell

    MsgBox "タイムスタンプを入力しました: " & Format(now, "yyyy/mm/dd hh:mm:ss"), vbInformation, "完了"

    Exit Sub

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