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

Excelのセル値に基づいて行を削除するにはどうすればよいですか?

Excelでセル値に基づいて複数の行をすばやく削除または削除するには、最初に特定のセル値を含む行全体を選択してから、それらを削除する必要がある場合があります。 セルの値に基づいて行を削除するのにVBAコードを使用する簡単な方法はないようです。 ここにあなたを助けるためのいくつかの簡単なトリックがあります。


検索と置換機能を使用して、セル値に基づいて行を削除します

Excelでは、強力な検索と置換機能を適用して、特定のセル値に基づいて行を簡単に削除できます。 次のようにしてください。

1。 特定のセル値に基づいて行を削除する範囲を選択し、を押して[検索と置換]ダイアログボックスを開きます。 Ctrl + F キーを同時に押す。

2。 [検索と置換]ダイアログボックスで、特定のセル値を入力してください(この場合、 ソー)を Find what ボックスをクリックし、 Find All ボタン。 以下の最初のスクリーンショットを参照してください。

3。 [検索と置換]ダイアログボックスの下部にあるすべての検索結果を選択し、このダイアログボックスを閉じます。 ((Note:検索結果のいずれかを選択してから Ctrl + A 見つかったすべての結果を選択するためのキー。 上記のXNUMX番目のスクリーンショットを参照してください。)
そして、特定の値を含むすべてのセルが選択されていることがわかります。

4。 選択したセルを右クリックして、 Delete 右クリックメニューから。 そして、 Entire row ポップアップする[削除]ダイアログボックスのオプションをクリックし、 OK ボタン。 これで、特定の値を含むすべてのセルが削除されたことがわかります。 以下のスクリーンショットを参照してください。

そして、すでに特定の値に基づいて行全体が削除されています。


VBAコードを使用してセル値に基づいて行を削除する

次のVBAコードを使用すると、特定のセル値を持つ行をすばやく削除できます。次の手順に従ってください。

1。 プレス Alt + F11 同時に開くキー Microsoft Visual Basic for applications 窓、

2に設定します。 OK をクリックします。 Insert > Module、および次のコードをモジュールに入力します。

VBA:セルの値に基づいて行全体を削除します

Sub DeleteRows()
'Updateby20211217
Dim rng As Range
Dim InputRng As Range
Dim DeleteRng As Range
Dim DeleteStr As String
Dim xTitleId As String
Dim xArr
Dim xF As Integer
Dim xWSh As Worksheet
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set rng = Application.Selection
Set InputRng = Application.InputBox("Range :", xTitleId, rng.Address, Type:=8)
If InputRng Is Nothing Then Exit Sub
DeleteStr = Application.InputBox("Delete Text", xTitleId, Type:=2)
Set xWSh = InputRng.Worksheet
For Each rng In InputRng
    If rng.Value = DeleteStr Then
        If DeleteRng Is Nothing Then
            Set DeleteRng = rng
        Else
            Set DeleteRng = Application.Union(DeleteRng, rng)
            Set DeleteRng = DeleteRng.EntireRow
        End If
    End If
Next
xArr = Split(DeleteRng.AddressLocal, ",")
DeleteRng.Select
DeleteRng.Delete
For xF = UBound(xArr) To 0 Step -1
    Set DeleteRng = xWSh.Range(xArr(xF))
    DeleteRng.Delete
Next
End Sub

3。 次に、 Run ボタンを押してコードを実行します。

4。 ポップアップダイアログボックスで、特定の値に基づいて行を削除する範囲を選択し、[ OK

5。 別のダイアログボックスで、行を削除する特定の値を入力して、 OK ボタン。 スクリーンショットを参照してください:

そして、指定された値に基づいて行全体がすでに削除されていることがわかります。


Kutools for Excelを使用して、XNUMXつまたはXNUMXつのセル値に基づいて行を削除します

あなたがインストールしている場合 Kutools for Excel、 その Select Specific Cells この機能は、特定の値を持つ行をすばやく削除するのに役立ちます。 次のようにしてください。

Kutools for Excel - 300 以上の必須ツールで Excel を強化します。 クレジット カードは必要なく、全機能を備えた 30 日間の無料トライアルをお楽しみください。 今すぐ入手

1。 特定の値に基づいて行を削除する範囲を選択し、をクリックします Kutools > Select > Select Specific Cells。 スクリーンショットを参照してください:

2。 [指定したセルを選択]ダイアログボックスを開いて、チェックしてください。 Entire row オプション、選択 Contains   Specific type ドロップダウンリストで、指定した値を右のボックスに入力し、[ Ok ボタン(上のスクリーンショットを参照)。
この機能を適用すると、ダイアログボックスが表示され、指定した基準に基づいて検出されたセルの数が表示されます。 クリックしてください OK ボタンを押して閉じます。

3。 これで、特定の値を持つ行全体が選択されます。 選択した行を右クリックして、 Delete 右クリックメニューから。 以下のスクリーンショットを参照してください。

Note:これ Select Specific Cells 機能は、XNUMXつまたはXNUMXつの特定の値で行を削除することをサポートします。 指定されたXNUMXつの値に基づいて行を削除するには、で別の値を指定してください Specific type 次のスクリーンショットのように、[特定のセルを選択]ダイアログボックスのセクション:

Kutools for Excel - 300 以上の必須ツールで Excel を強化します。 クレジット カードは必要なく、全機能を備えた 30 日間の無料トライアルをお楽しみください。 今すぐ入手


Kutools forExcelで複数のセル値に基づいて行を削除する

場合によっては、Excelの別の列/リストから複数のセル値に基づいて行を削除する必要があります。 ここで紹介します Kutools for Excel's Select Same & Different Cells 簡単にすばやく解決する機能。

Kutools for Excel - 300 以上の必須ツールで Excel を強化します。 クレジット カードは必要なく、全機能を備えた 30 日間の無料トライアルをお楽しみください。 今すぐ入手

1に設定します。 OK をクリックします。 Kutools > Select > Select Same & Different Cells [同じセルと異なるセルを選択]ダイアログボックスを開きます。

2。 オープニングで Select Same & Different Cells ダイアログボックスで、次のようにしてください(スクリーンショットを参照)。

で(1) Find values in ボックスで、特定の値が表示される列を選択してください。
で(2) According to ボックスで、行を削除する複数の値を持つ列/リストを選択してください。
で(3) Based on セクション、チェックしてください Each row オプション;
で(4) Find セクション、チェックしてください Same Values オプション;
(5)確認してください Select entire rows ダイアログボックスを開く下部にあるオプション。
Note:指定したXNUMXつの列に同じヘッダーが含まれている場合は、 My data has headers オプションを選択します。

3。 クリック Ok このユーティリティを適用するボタン。 次に、ダイアログボックスが表示され、選択された行数が表示されます。 クリックするだけです OK ボタンを押して閉じます。

そして、指定されたリストの中の値を含むすべての行が選択されました。

4に設定します。 OK をクリックします。 Home > Delete > Delete Sheet Rows 選択したすべての行を削除します。


デモ:ExcelのXNUMXつまたは複数のセル値に基づいて行を削除します


Kutools for Excel: 300 を超える便利なツールをすぐに利用できます。 機能制限なしの 30 日間の無料トライアルを今すぐ始めてください。 今すぐダウンロード!

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

🤖 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)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
In given range, if any cell contains defined text the entire row gets deleted.

Pls share code
This comment was minimized by the moderator on the site
Hi Yogesh,
On this webpage, the second method is to delete rows by cell values with VBA code. You can go to there and copy the code directly!
https://www.extendoffice.com/documents/excel/815-excel-remove-rows-based-on-cell-value.html#vba
This comment was minimized by the moderator on the site
There are two issues with the code posted as of this date. 1) the variable xTitleId is not declared, which causes a compilation error if Option Explicit is in use. 2) With Excel 2016, it appears that a range is limited to 129 areas. Each discontiguous matching cell found in the loop creates another area in the DeleteRng variable. Unfortunately, the Union method does not raise an error if that number of areas is exceeded; it just ignores the remaining cells. When the loop is finished, DeleteRng will have no more than 129 areas.
This comment was minimized by the moderator on the site
Hi TomTheToolman,
Thank you so much for your feedback. I've already updated the new code in the article. If you have any other questions, please don't hesitate to let me know.
Amanda
This comment was minimized by the moderator on the site
very well. Thank you!
This comment was minimized by the moderator on the site
Can someone help me...If 3rd column has value 0, then delete all values of corresponding column 1st. In this case answer should be the last line only.... Check MenuName ID 3149 VNLA MILFLLE 2 3149 TURKEY PNN 0 3149 R. BEEF PNN 0 3149 MIX MOCHA 38 3150 M.G.R 1/2 0 3150 THE PEPPE L 0 3150 MIX SLD 0 3150 EGGPLANT 0 3150 STILL WATER 7 3151 MIX MOCHA 38
This comment was minimized by the moderator on the site
Thanks for sharing. I am actually looking for a code that doesn't ask user for range but instead selects a specific column say column "A" and runs till the last row of that column. Can you please help..
This comment was minimized by the moderator on the site
Hi everybody, I am wondering what can we do to delete the following (According to the example shown in this page): Soe appears at several date (sept, October... etc). What I would like is to delete the line where Soe is but to keep the line with last date she appeared. In addition, some lines could be in double but I still want to keep it. So for example, you have the lines: - July 3 /Soe - Sep 4 / Soe - Sep 4 / Soe - Oct 19/ Soe - Nov 13 / Soe - Nov 13 / Soe and what I want to keep is: - Nov 13 / Soe - Nov 13 / Soe My real case is: I have different EAN code and version 1, 2, 3 or 4 and I want to keep the line where the version is the higher. e.g.: I have: - EAN 1 / Version 1 - EAN 1 / Version 1 - EAN 1 / Version 2 - EAN 1 / Version 2 - EAN 2 / Version 2 - EAN 2 / Version 3 - EAN 2 / Version 3 and I want to keep: - EAN 1 / Version 2 - EAN 1 / Version 2 - EAN 2 / Version 3 - EAN 2 / Version 3 I am searching since hours and I am completely blocked on this issue. Many thanks in advance for your brain and help. Best, Marion
This comment was minimized by the moderator on the site
Hi, Thank you this was really helpful. However, there's an error that pops up when I run the codes it says "Object variable or with block variable not set" and it points to " the line DeleteRNG.EntireRow.Delete". Could you please help me with debugging this. Thanks.
This comment was minimized by the moderator on the site
I am trying to use this macro in order to delete unused formulas, because excel views blank formula cells as a zero value and will print extra pages. I was hoping when I deleted the unused formulas, when I printed it would only print the pages that had information. This is not the case and I really need help to find a solution. I have tried using this formula and it is not working and prints three extra pages that I do not need even with the extra formulas being deleted. Sub selectonly() ' ' selectonly Macro ' Range("A1").Select Range(Selection, Selection.End(xlToRight)).Select Range(Selection, Selection.End(xlDown)).Select ExecuteExcel4Macro "PRINT(1,,,1,,,,,,,,2,,,TRUE,,FALSE)" End Sub
This comment was minimized by the moderator on the site
thank you so much. That save me a lot of time
This comment was minimized by the moderator on the site
Trying to find a delete Function that will delete entire designated rows automatically, based on certain values or certain text contained in other cell(s), using only automated formulas.
This comment was minimized by the moderator on the site
How can i delete selected cell that i want based on value that i entered for example : A1 B1 C1 D1 A2 B2 C2 D2 A3 B3 C3 D3 A4 B4 C4 D4 When i entered in some cell for example "2" then 2 row will be deleted from A3:D4. If i entered "1" then 1 row will be deleted from A4:D4. if i entered "3" then 3 row will be deleted from A2:D4
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