メインコンテンツへスキップ

Excelで特定の行数を一定の間隔で挿入するにはどうすればよいですか?

Excelワークシートでは、挿入機能を使用して、既存の行の間に空白行を挿入できます。 しかし、データの範囲が広く、XNUMX行ごとにXNUMX行の空白行を挿入する必要がある場合、このジョブをすばやく便利に完了するにはどうすればよいでしょうか。


VBAコードを使用して、特定の数の空白行を一定の間隔でデータ範囲に挿入します

次のVBAコードは、既存のデータ内のn行ごとに特定の行数を挿入するのに役立ちます。 次のようにしてください。

1。 を押し続けます Alt + F11 Excelでキーを押すと、 アプリケーション向け Microsoft Visual Basic 窓。

2に設定します。 OK をクリックします。 インセット > モジュール、次のコードをに貼り付けます モジュールウィンドウ.

VBAコード:特定の行数を一定の間隔でデータに挿入します

Sub InsertRowsAtIntervals()
'Updateby Extendoffice
Dim Rng As Range
Dim xInterval As Integer
Dim xRows As Integer
Dim xRowsCount As Integer
Dim xNum1 As Integer
Dim xNum2 As Integer
Dim WorkRng As Range
Dim xWs As Worksheet
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
xRowsCount = WorkRng.Rows.Count
xInterval = Application.InputBox("Enter row interval. ", xTitleId, 1, Type:=1)
xRows = Application.InputBox("How many rows to insert at each interval? ", xTitleId, 1, Type:=1)
xNum1 = WorkRng.Row + xInterval
xNum2 = xRows + xInterval
Set xWs = WorkRng.Parent
For i = 1 To Int(xRowsCount / xInterval)
    xWs.Range(xWs.Cells(xNum1, WorkRng.Column), xWs.Cells(xNum1 + xRows - 1, WorkRng.Column)).Select
    Application.Selection.EntireRow.Insert
    xNum1 = xNum1 + xNum2
Next
End Sub

3. このコードを貼り付けたら、を押してください F5 このコードを実行するためのキーを押すと、空白行を挿入するデータ範囲を選択するように促すプロンプトボックスが表示されます。スクリーンショットを参照してください。

4に設定します。 OK をクリックします。 OK ボタンをクリックすると、別のプロンプトボックスが表示されます。行間隔の数を入力してください。スクリーンショットを参照してください。

5。 クリックしてください OK ボタンをクリックして、次のポップアッププロンプトボックスに、挿入する空白行の数を入力してください。スクリーンショットを参照してください。

6。 次に、をクリックします OK、および空白行が定期的に既存のデータに挿入されています。スクリーンショットを参照してください。


VBAコードのセル値に基づいて、特定の数の空白行をデータ範囲に挿入します

セル値のリストに基づいて空白行を挿入する必要がある場合があります。この場合、以下のVBAコードを使用すると、次のようになります。

1。 を押し続けます Alt + F11 Excelでキーを押すと、 アプリケーション向け Microsoft Visual Basic 窓。

2に設定します。 OK をクリックします。 インセット > モジュール、次のコードをに貼り付けます モジュールウィンドウ.

VBAコード:番号のリストに基づいて特定の数の空白行を挿入します。

Sub Insertblankrowsbynumbers ()
'UpdatebyExtendoffice
Dim xRg As Range
Dim xAddress As String
Dim I, xNum, xLastRow, xFstRow, xCol, xCount As Long
On Error Resume Next
xAddress = ActiveWindow.RangeSelection.Address
Set xRg = Application.InputBox("Select the spefic number column to use(single column):", "Kutools For Excel", xAddress, , , , , 8)
If xRg Is Nothing Then Exit Sub
Application.ScreenUpdating = False
xLastRow = xRg(1).End(xlDown).Row
xFstRow = xRg.Row
xCol = xRg.Column
xCount = xRg.Count
Set xRg = xRg(1)
For I = xLastRow To xFstRow Step -1
xNum = Cells(I, xCol)
If IsNumeric(xNum) And xNum > 0 Then
Rows(I + 1).Resize(xNum).Insert
xCount = xCount + xNum
End If
Next
xRg.Resize(xCount, 1).Select
Application.ScreenUpdating = True
End Sub

3。 このコードを貼り付けたら、を押します F5 このコードを実行するためのキー。ポップアウトされたダイアログボックスで、空白行を挿入する番号のリストを選択します。スクリーンショットを参照してください。

4。 次に、をクリックします。 OK、次のスクリーンショットのように、必要な結果が得られます。


便利な機能を使用して、特定の数の空白行を一定の間隔でデータ範囲に挿入します

上記のVBAコードに慣れていない場合は、 Kutools for Excel また、あなたを助けるかもしれません、その 空白の行と列を挿入する 機能は、特定の数の行または列を一定の間隔で既存のデータにすばやく簡単に挿入できます。

注:これを適用する 空白の行と列を挿入する 、まず、ダウンロードする必要があります Kutools for Excel、次に機能をすばやく簡単に適用します。

インストールした後 Kutools for Excel、次のようにしてください。

1。 空白行を間隔を置いて挿入するデータ範囲を選択します。

2に設定します。 OK をクリックします。 クツール > インセット > 空白の行と列を挿入する、スクリーンショットを参照してください:

3。 の中に 空白の行と列を挿入する ダイアログボックスで、 空白行 からのオプション 挿入タイプ、次に、次のスクリーンショットのように、使用する間隔と空白行の数を指定します。

4。 次に、をクリックします OK 次のスクリーンショットに示すように、ボタンをクリックすると、空白の行が特定の間隔で選択した範囲に挿入されます。

今すぐExcel用のKutoolsをダウンロードして無料トライアル!


VBAコードを使用して、特定の番号に基づいて行を複数回コピーおよび挿入します

ある範囲の多田があり、次のスクリーンショットに示すように、各行をコピーして、番号のリストに基づいて次の行に複数回貼り付けたいとします。 Excelワークシートでこのタスクをどのように解決できますか?

この仕事に対処するために、私はあなたに役立つコードを紹介します。次の手順で実行してください。

1。 を押し続けます Alt + F11 Excelでキーを押すと、 アプリケーション向け Microsoft Visual Basic 窓。

2に設定します。 OK をクリックします。 インセット > モジュール、次のコードをに貼り付けます モジュールウィンドウ.

VBAコード:特定の番号に基づいて行を複数回コピーおよび挿入します。

Sub CopyRows()
'UpdatebyExtendoffice
Dim xRg As Range
Dim xCRg As Range
Dim xFNum As Integer
Dim xRN As Integer
On Error Resume Next
SelectRange:
xTxt = ActiveWindow.RangeSelection.Address
Set xRg = Application.InputBox("Select the list of numbers to copy the rows based on: ", "Kutools for Excel", xTxt, , , , , 8)
If xRg Is Nothing Then Exit Sub

If xRg.Columns.Count > 1 Then
MsgBox "Please select single column!"
GoTo SelectRange
End If
Application.ScreenUpdating = False
For xFNum = xRg.Count To 1 Step -1
Set xCRg = xRg.Item(xFNum)
xRN = CInt(xCRg.Value)
With Rows(xCRg.Row)
.Copy
.Resize(xRN).Insert
End With
Next
Application.ScreenUpdating = True
End Sub

3。 このコードを貼り付けたら、を押します F5 このコードを実行するためのキー。ポップアウトされたダイアログボックスで、コピーする数値のリストを選択し、それに基づいてデータ行を挿入します。スクリーンショットを参照してください。

4。 次に、をクリックします。 OK ボタンをクリックすると、特定の行数がコピーされて元の各行の下に貼り付けられます。スクリーンショットを参照してください。


驚くべき機能を備えた特定の番号に基づいて、行を複数回コピーおよび挿入します

あなたが持っている場合 Kutools for Excelそのと セル値に基づいて行/列を複製する この機能を使用すると、数値のリストに基づいて行または列をすばやく簡単に挿入できます。

注:これを適用する セル値に基づいて行/列を複製する、まず、ダウンロードする必要があります Kutools for Excel、次に機能をすばやく簡単に適用します。

インストールした後 Kutools for Excel、次のようにしてください。

1に設定します。 OK をクリックします。 クツール > インセット > セル値に基づいて行/列を複製する、スクリーンショットを参照してください:

2。 の中に 行と列をコピーして挿入する ダイアログボックスで 行をコピーして挿入する 内のオプション セクションで、複製するデータ範囲を選択し、行のコピーに基づく値のリストを指定します。スクリーンショットを参照してください。

4。 次に、をクリックします。 Ok or 申し込む ボタンをクリックすると、必要に応じて次の結果が得られます。

今すぐExcel用のKutoolsをダウンロードして無料トライアル!

より相対的な記事:

  • 行を複数回コピーして挿入するか、行をX回複製します
  • 日常業務で、行または各行をコピーしてから、ワークシートの現在のデータ行の下に複数回挿入しようとしたことがありますか? たとえば、セルの範囲があります。次に、次のスクリーンショットのように、各行をコピーして次の行に3回貼り付けます。 Excelでこの仕事にどのように対処できますか?
  • Excelで値が変更されたときに空白行を挿入する
  • データの範囲があり、値が変更されたときにデータの間に空白行を挿入して、次のスクリーンショットのようにXNUMXつの列で連続する同じ値を区切ることができるとします。 この記事では、この問題を解決するためのいくつかの秘訣について説明します。
  • 基準に基づいて複数のワークシートから新しいシートに行をコピーする
  • 以下のスクリーンショットと同じフォーマットのXNUMXつのワークシートを含むワークブックがあるとします。 ここで、列Cに「Completed」というテキストが含まれているこれらのワークシートのすべての行を新しいワークシートにコピーします。 手動でXNUMXつずつコピーして貼り付けることなく、この問題をすばやく簡単に解決するにはどうすればよいでしょうか。

最高のオフィス生産性向上ツール

🤖 Kutools AI アシスタント: 以下に基づいてデータ分析に革命をもたらします。 インテリジェントな実行   |  コードを生成  |  カスタム数式の作成  |  データを分析してグラフを生成する  |  Kutools関数を呼び出す...
人気の機能: 重複を検索、強調表示、または識別する   |  空白行を削除する   |  データを失わずに列またはセルを結合する   |   数式なしのラウンド ...
スーパールックアップ: 複数の基準の VLookup    複数の値の VLookup  |   複数のシートにわたる VLookup   |   ファジールックアップ ....
詳細ドロップダウン リスト: ドロップダウンリストを素早く作成する   |  依存関係のドロップダウン リスト   |  複数選択のドロップダウンリスト ....
列マネージャー: 特定の数の列を追加する  |  列の移動  |  Toggle 非表示列の表示ステータス  |  範囲と列の比較 ...
注目の機能: グリッドフォーカス   |  デザインビュー   |   ビッグフォーミュラバー    ワークブックとシートマネージャー   |  リソースライブラリ (自動テキスト)   |  日付ピッカー   |  ワークシートを組み合わせる   |  セルの暗号化/復号化    リストごとにメールを送信する   |  スーパーフィルター   |   特殊フィルター (太字/斜体/取り消し線をフィルター...) ...
上位 15 のツールセット12 テキスト ツール (テキストを追加, 文字を削除する、...)   |   50+ チャート 種類 (ガントチャート、...)   |   40+ 実用的 (誕生日に基づいて年齢を計算する、...)   |   19 挿入 ツール (QRコードを挿入, パスから画像を挿入、...)   |   12 変換 ツール (数字から言葉へ, 通貨の換算、...)   |   7 マージ&スプリット ツール (高度な結合行, 分割セル、...)   |   ... もっと

Kutools for Excel で Excel スキルを強化し、これまでにない効率を体験してください。 Kutools for Excelは、生産性を向上させ、時間を節約するための300以上の高度な機能を提供します。  最も必要な機能を入手するにはここをクリックしてください...

説明


Officeタブは、タブ付きのインターフェイスをOfficeにもたらし、作​​業をはるかに簡単にします

  • Word、Excel、PowerPointでタブ付きの編集と読み取りを有効にする、パブリッシャー、アクセス、Visioおよびプロジェクト。
  • 新しいウィンドウではなく、同じウィンドウの新しいタブで複数のドキュメントを開いて作成します。
  • 生産性を 50% 向上させ、毎日何百回もマウス クリックを減らすことができます!
Comments (39)
Rated 5 out of 5 · 2 ratings
This comment was minimized by the moderator on the site
Marvelous vba script!
I had over 5000 rows that i need to add new rows to in between. All other guides told me to make "helper" column it would take me good part of my life to add 1,2 copy paste over and over again just to add new rows.
So, Thanks for this!
Rated 5 out of 5
This comment was minimized by the moderator on the site
hola, hay algun codigo que me permita copiar los datos, pero que en la primera columna que son fechas puedan ser consecutivas.

ejemplo

en vez de que quede asi

10/01/2022 19.258.369-4 Juan Ramirez
10/01/2022 19.258.369-4 Juan Ramirez
10/01/2022 19.258.369-4 Juan Ramirez

quede asi

10/01/2022 19.258.369-4 Juan Ramirez
11/01/2022 19.258.369-4 Juan Ramirez
12/01/2022 19.258.369-4 Juan Ramirez

gracias
This comment was minimized by the moderator on the site
hola, hay algun codigo que me permita copiar los datos, pero que en la primera columna que son fechas pueda ser consecutivo.

ejemplo

en vez de que quede asi

01/10/2022 19.258.369-4 Juan Ramirez
01/10/2022 19.258.369-4 Juan Ramirez
01/10/2022 19.258.369-4 Juan Ramirez

quede asi

01/10/2022 19.258.369-4 Juan Ramirez
02/10/2022 19.258.369-4 Juan Ramirez
03/10/2022 19.258.369-4 Juan Ramirez

gracias
This comment was minimized by the moderator on the site
Name Email Phone Address
0 Name Email Phone Adress
address line 2 Name Phone 0
Name Email Phone Adress
0 Name Email Phone Adress
address line 2 0


How could I edit this to start a new row at every empty value or 0 value without having phone numbers with 0 start a new row?
This comment was minimized by the moderator on the site
Hello, Jarrod

Sorry, I can't get your problem clearly.
Could you explain your problem more detailed? Or you can insert a screenshot or file here.
Thank you!
This comment was minimized by the moderator on the site
Вот выручили так выручили!
Сидел, ломал голову как добавить строки по заданному количеству.
Ваш макрос мне очень помог.
Rated 5 out of 5
This comment was minimized by the moderator on the site
can you tell me how to insert column like this way , what is the code
This comment was minimized by the moderator on the site
Hello friend,
You can use this VBA code:

Sub InsertColumnsAtIntervals()

'Updateby Extendoffice

Dim Rng As Range

Dim xInterval As Integer

Dim xColumns As Integer

Dim xColumnsCount As Integer

Dim xNum1 As Integer

Dim xNum2 As Integer

Dim WorkRng As Range

Dim xWs As Worksheet

xTitleId = "KutoolsforExcel"

Set WorkRng = Application.Selection

Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)

xColumnsCount = WorkRng.Columns.Count

xInterval = Application.InputBox("Enter column interval. ", xTitleId, 1, Type:=1)

xColumns = Application.InputBox("How many columns to insert at each interval? ", xTitleId, 1, Type:=1)

xNum1 = WorkRng.Column + xInterval

xNum2 = xColumns + xInterval

Set xWs = WorkRng.Parent

For i = 1 To Int(xColumnsCount / xInterval)

    xWs.Range(xWs.Cells(WorkRng.Row, xNum1), xWs.Cells(WorkRng.Row, xNum1 + xColumns - 1)).Select

    Application.Selection.EntireColumn.Insert

    xNum1 = xNum1 + xNum2

Next

End Sub


Sincerely,
Mandy
This comment was minimized by the moderator on the site
Muito obrigado, salvou meu trabalho, eu não tinha ideia de como fazer. Muito obrigado mesmo!
This comment was minimized by the moderator on the site
Hello,
You are welcome. Glad it helps. Any questions, please feel free to contact us. Have a great day.
Sincerely,
Mandy
This comment was minimized by the moderator on the site
This is so Cool!! Thanks a lot
This comment was minimized by the moderator on the site
Can I get the VBA code for deletion of rows based on duplicate values in a selected column keeping all unique values?
This comment was minimized by the moderator on the site
Hello, Roy,If you want to remove rows based on duplicate values, normally, you can use the Remove Duplicates feature in Excel to remove the rows.Of course, if you need a VBA code, please use the below code: (First, you should select the data range that you want to remove, and then run this code, the rows based on the duplicate values in the first column of your selection will be removed at once. )<div data-tag="code">Sub Delete_duplicate_rows()
Dim Rng As Range
Set Rng = Selection
Rng.RemoveDuplicates Columns:=Array(1), Header:=xlYes
End SubPlease try, hope it can help you!
This comment was minimized by the moderator on the site
Thank you author! You deserve the best commendation for these! But please could you help me out with the code to put a constant value into all blank rows I created with your code above? To make myself more clearer, I need to insert a constant value into all blank rows (this solved already with your code above) then I need to insert a constant value into all of the blank rows (this is my problem). Thank you as I expect your kind response.
This comment was minimized by the moderator on the site
Hello, Do you mean to fill blank rows with specific value? If so, mabe the following article cna help you:https://www.extendoffice.com/documents/excel/772-excel-fill-blank-cells-with-0-or-specific-value.html
Please try it.
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations