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

Excelで値が変更されたときに空白行を挿入するにはどうすればよいですか?

データの範囲があり、値が変更されたときにデータの間に空白行を挿入して、次のスクリーンショットのようにXNUMXつの列で連続する同じ値を区切ることができるとします。 この記事では、この問題を解決するためのいくつかの秘訣について説明します。

小計関数で値が変更されたときに空白行を挿入する

ヘルパー列で値が変更されたときに空白行を挿入する

VBAコードで値が変更されたときに空白行を挿入する

強力な機能で値が変更されたときに特定の数の空白行を挿入する


小計関数で値が変更されたときに空白行を挿入する

合計 この機能では、次の手順に従って、値が変更されたときにデータの間に空白行を挿入できます。

1。 使用するデータ範囲を選択します。

2に設定します。 OK をクリックします。 且つ > 合計 を開く 合計 ダイアログボックス、および 合計 ダイアログで、次のオプションを実行してください。

1:値がいつ変更されるかに基づいて、空白行を挿入する列名を選択します。 変更のたびに セクションで;
2:選択 ワンランク上の 関数を使用します ドロップダウンリスト;
3:小計を挿入する列名をチェックします 小計をに追加 リストボックス

3。 次に、をクリックします OK、小計行が異なる製品の間に挿入され、アウトライン記号が表の左側に表示されます。スクリーンショットを参照してください。

4。 次に、アウトライン記号の上部にある番号2をクリックして、小計行のみを表示します。

5。 次に、小計範囲データを選択し、を押します Alt +; 表示されている行のみを選択するためのショートカットキー。スクリーンショットを参照してください。

6。 表示されている行のみを選択した後、を押します 削除 キーボードのキーを押すと、すべての小計行が削除されました。

7。 次に、他のセルをクリックして、戻ります 且つ > グループ解除 > 明確なアウトライン アウトラインを削除するには、スクリーンショットを参照してください。

8。 アウトラインシンボルがすぐにクリアされ、値が変更されたときにデータ間に空白行が挿入されていることがわかります。スクリーンショットを参照してください。

9。 最後に、必要に応じて列Aを削除できます。


値が急速に変化する場合は、改ページ、空白行、下枠、または塗りつぶしの色を挿入します

あなたが持っている場合 Kutools for Excel's 違いを区別する この機能を使用すると、必要に応じて値が変更されたときに、改ページ、空白行、下枠、または塗りつぶしの色をすばやく挿入できます。 以下のデモを参照してください。         クリックしてKutoolsfor Excelをダウンロードしてください!


ヘルパー列で値が変更されたときに空白行を挿入する

ヘルパー列を使用すると、最初に数式を挿入してから、 検索および置換 関数は、最後に、変化する値の間に空白行を挿入します。 次のようにしてください。

1。 空白のセルC3に、この数式を入力してください = A3 = A2、およびセルD4にこの数式を入力します = A4 = A3、スクリーンショットを参照してください:

2。 次に、C3:D4を選択し、これらの数式を適用する範囲まで塗りつぶしハンドルをドラッグすると、次のようになります。 or × セル内のスクリーンショットを参照してください。

3。 そして、 Ctrl + F キーを押して 検索および置換 ダイアログ、ポップアウトされたダイアログで、 間違った情報見つける 下のテキストボックス もう完成させ、ワークスペースに掲示しましたか? タブをクリックして オプション ボタンをクリックしてこのダイアログを展開し、 価値観 覗く ドロップダウンリスト、スクリーンショットを参照してください:

4. すべて検索 ボタンをクリックし、を押します Ctrlキー+ A 検索のすべての結果を選択するには、すべてのFALSEセルが一度に選択されています。スクリーンショットを参照してください。

6。 閉じます 検索および置換 ダイアログ、次のステップ、クリックして空白行を挿入できます ホーム > インセット > シート行を挿入、および列Aに基づいて値が変更されると、データに空白行が挿入されます。スクリーンショットを参照してください。

7。 最後に、必要に応じてヘルパー列CおよびDを削除できます。


VBAコードで値が変更されたときに空白行を挿入する

上記の方法を使用するのにうんざりしている場合は、変更された値の間に空白行を一度に挿入するのに役立つコードがあります。

1。 を押し続けます Alt + F11 キーを押して Microsoft Visual Basic forApplicationsウィンドウ.

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

VBAコード:値が変更されたときに空白行を挿入します

Sub InsertRowsAtValueChange()
'Update by Extendoffice
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Application.ScreenUpdating = False
For i = WorkRng.Rows.Count To 2 Step -1
    If WorkRng.Cells(i, 1).Value <> WorkRng.Cells(i - 1, 1).Value Then
        WorkRng.Cells(i, 1).EntireRow.Insert
    End If
Next
Application.ScreenUpdating = True
End Sub

3。 次に、 F5 このコードを実行するためのキーを押すと、プロンプトボックスが表示され、値が変更されたときに空白行を挿入するXNUMXつの列データを選択できます。スクリーンショットを参照してください。

4。 そして、 OK、列Aに基づいて値が変更されると、データ間に空白行が挿入されます。


強力な機能で値が変更されたときに特定の数の空白行を挿入する

上記の面倒な方法を試してみたら、ここでは便利なツールを紹介します。 Kutools for Excel's 違いを区別する セルの値がすばやく簡単に変更されたときに、改ページ、空白行、下の境界線、または塗りつぶしの色を挿入するのに役立ちます。

ヒント:これを適用する 違いを区別する 機能、まず、ダウンロードする必要があります Kutools for Excel、次に機能をすばやく簡単に適用します。

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

1に設定します。 OK をクリックします。 クツール > フォーマット > 違いを区別する、スクリーンショットを参照してください:

2。 の中に キー列で違いを区別する ダイアログボックスで、次の操作を行ってください。

  • 使用するデータ範囲を選択してから、空白行を挿入するキー列を選択します。
  • 次に確認してください 空白行 オプションから オプション セクションをクリックし、挿入する空白行の数を入力します。

3。 次に、をクリックします Ok ボタンをクリックすると、セル値が変更された場合に特定の数の空白行がデータに挿入されます。スクリーンショットを参照してください。

クリックしてKutoolsfor Excelと無料トライアルを今すぐダウンロードしてください!

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

🤖 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 (16)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hi, Hassan,

This vba is amazing, whereas I need one more alternate code for insert single blank row after changes in sequencing numbers. Example:- In column having number series like 1, 2, 3, 5, 6, 9 & etc...
Need to add single blank row between 3 & 5 as well as 6 & 9.
Please can you with this.
This comment was minimized by the moderator on the site
Can the VBA method be adapted to ignore blank cells? I have a file which I need to insert rows in based on two different columns but when I run the macro on the second column I end up with three blank lines where the first macro run inserted rows.
Or can it run on two columns at the same time?
This comment was minimized by the moderator on the site
Hello,
Is very usefull in case i need to insert 1 row, but if i need to insert 145 rows in every time the data change in spwcific column, how can i do it??
This comment was minimized by the moderator on the site
Hi, Hassan,
To insert multiple blank rows when value changes in a specific column, you should apply the following VBA code:

Note: In the below code, you should change the number 99 to your need, for example, when you insert 145 blank rows, you should change the number 99 to 144. Please try it, hope it can help you!

Sub InsertRowsAtValueChange()
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Application.ScreenUpdating = False
For i = WorkRng.Rows.Count To 2 Step -1
If WorkRng.Cells(i, 1).Value <> WorkRng.Cells(i - 1, 1).Value Then
Range(WorkRng.Cells(i, 1).EntireRow, WorkRng.Cells(i + 99, 1).EntireRow).Insert
End If
Next
Application.ScreenUpdating = True
End Sub
This comment was minimized by the moderator on the site
Very helpful. The code that skyyang shows above worked perfectly. Just make sure that the data doesn't already have spaces in it.

I don't understand VBA, but I believe if you wanted to add more rows underneath data that already had the spacing, there should be a way to ignore spaces.

Could a line be added to ignore or skip over blank lines? That might make this code more universal and repeatable if needed. Also a delete function that is similar to this may be useful so undo isn't necessary.
This comment was minimized by the moderator on the site
RE: insert blank rows when value changes with vba code
Is there a way that I can save the Range & not have to pick it every time I run it?
This comment was minimized by the moderator on the site
The VBA code worked 1st time and did exactly what I was trying to do. Thank you so much!
This comment was minimized by the moderator on the site
I've been using my own solution for some time.
1. Insert a helper column into Column A
2. In A2, type "if(B2=B1,A1,A1+1)"
3. Copy that formula down to the last row
4. Copy all the populated cells in column A and Paste Special (Values) over them
5. Copy all the cells again and paste them into column A in the first unpopulated cell (e.g. if you have 104 rows of data plus a header row you would paste into cell A106)
6. Click on Data and Remove Duplicates (only on the cells you just pasted in Step 5; not on all rows)
7. Sort all of Column A
8. Delete Column A

Seems like a lot of steps but only takes a few seconds.
This comment was minimized by the moderator on the site
[quote]Hi all thank you!! its awesome , can you guys also let me how to insert 2 rows when the value changes in VBA or through excel.By Hudson[/quote] Please let me know how to insert more than 1 row.
This comment was minimized by the moderator on the site
Hi there, These are almost useful! The first method doesn't work for me because when I follow the steps explicitly, the the data that I delete in the subtotal panes deletes the entire columns that I've sorted. In the second method when I get to the step where I insert sheet rows, the rows are inserted ABOVE the FALSE cells which breaks up the data, but the last selection of every group is then added to the group below. Any advice???
This comment was minimized by the moderator on the site
Hi all thank you!! its awesome , can you guys also let me how to insert 2 rows when the value changes in VBA or through excel.
This comment was minimized by the moderator on the site
Where in the code would I need to modify to include more than one row, I need to add 10 after each break... Thanks
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