1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

下から上まで指定した範囲で空白行を挿入

Last updated at Posted at 2024-03-22
Sub InsertBlankRowsAtIntervals()
    Dim ws As Worksheet
    Dim lastRow As Long, n As Long, i As Long
    Dim colC As Long, lastCol As Long
    
    ' カスタマイズ可能な変数
    n = 5 ' ここでnの値を設定します。n行ごとに空白行を挿入
    
    Set ws = ActiveSheet
    lastRow = ws.Cells(ws.Rows.Count, "C").End(xlUp).Row ' C列での最後の行を取得
    lastCol = ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column ' 最後の列を取得
    
    ' 最後の行から始めて、n行ごとに繰り返し
    For i = lastRow To 2 Step -n
        ws.Rows(i + 1 & ":" & i + 1).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
        ' 挿入した空白行のC列から右端までの範囲を選択
        ws.Range(ws.Cells(i + 1, 3), ws.Cells(i + 1, lastCol)).Select
    Next i
End Sub
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?