跳到主要内容

根据 Excel 中的单元格值删除行 – 简单教程

无论您处理的是小型电子表格还是大型数据集,了解如何根据单元格值删除行都可以节省您的时间和精力。此过程可以使用多种 Excel 功能来执行,包括筛选功能、查找和替换工具、排序功能,甚至可以使用高级技术。在本指南结束时,您将具备从 Excel 工作表中有效删除不需要的行的知识,确保您的数据干净且符合您的分析需求。

例如,如果我想删除 name 列包含 Jener 的所有行,我该如何进行?

根据单元格值删除整行

使用排序功能根据单元格值删除选择中的行


根据 Excel 中的单元格值删除整行

Excel 提供了多种根据特定单元格值删除行的方法。本节涵盖的方法范围从简单的 Excel 功能(如过滤、查找和替换和 Kutools)到涉及 VBA 的更高级技术。无论您是初学者还是高级用户,您都会找到适合您的技能水平和需求的方法。

📝 备注:以下删除行的方法将删除该行中的所有数据,包括该行其他单元格中的内容。为了防止数据丢失,请考虑在删除之前将数据集复制到另一个工作表上。

使用过滤器功能根据单元格值删除整行

通常,您可以应用过滤功能来显示符合特定条件的行,然后立即删除该行。

步骤1:应用过滤功能过滤掉不需要的行

  1. 选择要删除行的数据范围。然后,单击 时间 > 筛选器,请参见屏幕截图:
  2. 现在,下拉箭头将出现在每列的标题中。单击包含要根据其删除行的值的列中的下拉箭头。例如,如果您要删除名称为 Jener 的行,则可以单击“名称”列中的箭头。
  3. 在下拉菜单中,取消选中 选择全部 清除所有选择,然后仅选中 Jener 旁边的框,或在搜索框中手动输入 Jener 以快速找到它。
  4. 然后,单击 OK 按钮来应用过滤器。仅显示包含 Jener 的行。看截图:

步骤 2:删除筛选的行

选择可见行,然后右键单击所选行之一并选择 删除行 从上下文菜单中。这将删除所有选定的行。

步骤 3:清除过滤器

然后,点击 时间 > 筛选器 再次。这将删除过滤器,您将看到除已删除记录之外的所有记录。

???? Tips:
  • 与我应用过滤方法来消除包含文本 Jener 的行类似,您也可以利用它根据数字或日期条件删除行,如以下屏幕截图所示:
    号码过滤条件:


    日期过滤条件:
  • 您还可以使用“过滤器”功能来过滤和删除包含特定背景颜色的所有行。看截图:
  • 您可以使用过滤功能根据多个条件进行过滤,过滤掉不需要的内容,然后将其删除。例如,假设您要删除销售员为 Jener 并且总销售额大于 7000 美元的所有行。您应该首先按名称 Jener 过滤行,然后过滤销售额大于 7000 的行。
 

使用 Kutools AI Aide 根据单元格值删除整行

Kutools for Excel 是一个综合性加载项,包含 300 多个高级功能,旨在简化 Excel 中的各种复杂任务。它的特点之一是, Kutools 人工智能助手,有助于自动执行任务,例如根据特定条件过滤和删除行。

📝 备注: 要使用这个 Kutools 人工智能助手 of Kutools for Excel下载并安装 Kutools for Excel 第一。

安装后 Kutools for Excel请点击 Kutools人工智能 > 人工智能助手 打开 Kutools 人工智能助手 窗格:

  1. 选择数据范围,然后在聊天框中输入您的要求,然后单击 提交 按钮或按下 输入 发送问题的键;
    “如果“名称”列在选择中包含名称 Jener,则删除行”
  2. 分析完后点击 执行 按钮运行。 Kutools AI Aide 将使用 AI 处理您的请求并直接在 Excel 中删除指定的行。
???? Tips:
  • 要根据多个条件删除行,只需相应地调整要求即可。例如,使用类似“删除所选内容中“名称”列包含 Jener 或 Kevin 的行“或”删除所选内容中“名称”列包含 Jener 且总销售额超过 7000 的行".
  • 这种方法 不支持撤消 功能。但是,如果您想恢复原始数据,您可以单击 不满意 还原更改。
 

使用查找和替换功能根据单元格值删除整行

使用 Excel 的查找和替换功能根据特定单元格值删除整行是一种简单的方法,可以非常有效地清理数据。请按以下步骤操作:

步骤 1:应用查找和替换功能来选择特定值

  1. 选择要根据特定单元格值删除行的列数据,然后打开 查找和替换 对话框,方法是按 Ctrl + F 键同时。
  2. 查找和替换 对话框中,请键入特定的单元格值(在我们的例子中,我们输入 耶纳) 进入 查找内容 框,然后单击 找到所有 按钮。 看截图:
  3. 选择底部的所有搜索结果 查找和替换 对话框,然后关闭该对话框。 (您可以选择其中一项搜索结果,然后 按Ctrl + A 键选择所有找到的结果。)并且包含特定值的所有单元格都被选择。然后,关闭该对话框。看截图:

步骤 2:根据所选值删除行

  1. 在单元格仍处于选中状态的情况下,右键单击选定的单元格之一,然后选择 删除 从上下文菜单。
  2. 选择 整行 在“删除”对话框中,然后单击 OK 删除包含指定值的所有行。
 

使用 VBA 代码根据单元格值删除整行

在 Excel 中使用 VBA(Visual Basic for Applications)根据单元格值删除行可以实现任务自动化,从而提高效率,尤其是对于大型数据集。

第 1 步:打开 VBA 模块编辑器并复制代码

  1. 媒体 Alt + F11键 键打开 Microsoft Visual Basic应用程序 窗口。
  2. 在打开的窗口中,单击 插页 > 模块 创建一个新的空白模块。
  3. 然后,将以下代码复制并粘贴到空白模块中。
    Sub DeleteRowsBasedOnCellValue()
    'Updateby Extendoffice
        Dim ws As Worksheet
        Set ws = ActiveSheet
        Dim columnRange As Range
        On Error Resume Next
        Set columnRange = Application.InputBox("Select the column range to check:", "Kutools for Excel", Type:=8)
        On Error GoTo 0
        If columnRange Is Nothing Then Exit Sub
        Dim lastRow As Long
        lastRow = ws.Cells(ws.Rows.Count, columnRange.Column).End(xlUp).Row
        Dim criteria As String
        criteria = Application.InputBox("Enter the value to delete rows for:", "Kutools for Excel", Type:=2)
        If criteria = "" Then Exit Sub
        Dim i As Long
        For i = lastRow To 1 Step -1
            If ws.Cells(i, columnRange.Column).Value = criteria Then
                ws.Rows(i).Delete
            End If
        Next i
    End Sub
    

第2步:执行代码

  1. 然后按 F5 键来运行代码。在弹出的对话框中,选择要根据特定值删除行的列,然后单击 OK 按钮。
  2. 在以下对话框中,请键入要删除行的特定值,然后单击 OK 按钮。 看截图:

结果:

然后您将看到已经基于指定的值删除了整个行。

📝 备注:这个VBA代码方法 不支持撤消,因此在使用之前请确保操作按预期执行。此外,建议维护数据备份,以防止意外更改或丢失。

使用排序功能根据单元格值删除选择中的行

上述所有方法都会删除整行,这可能是一个限制。例如,使用这些方法将消除数据集右侧的所有数据。假设您希望仅删除数据集中的某些记录,同时保留其余数据。在这种情况下,需要采用替代方法。

步骤 1:为数据创建辅助列

创建一个新列,这将帮助我们跟踪订单。您需要在数据旁边插入一列,然后用序列号填充它,例如 1、2、3…请参见屏幕截图:

步骤2:根据特定列对数据进行排序

  1. 选择要删除行所依据的数据列。然后,单击 时间 > 将A到Z排序 or Z到A,弹出排序警告对话框,选择 扩大选择,然后单击 排序 按钮。 看截图:
  2. 现在,具有相同值的行将被分组在一起,以便于识别和选择它们。看截图:

步骤 3:删除已排序的行

  1. 选择要删除的记录组,然后右键单击,然后选择 删除 从上下文菜单中。 在里面 删除 对话框中选择 向上移动单元格 选项。然后,单击 OK 按钮看截图:
  2. 仅删除名称为 Jener 的记录,而不删除整行。因此,数据集右侧或左侧的任何数据都将不受影响。

步骤 4:应用排序功能恢复数据的原始顺序

单击帮助列的标题,然后转至 时间 在功能区上并选择 将A到Z排序 根据辅助列中的顺序组织数据。这将根据需要将所选范围内的数据恢复为其原始顺序。

第 5 步:删除辅助列

最后,根据需要删除辅助列以清理工作表。


在本文中,我们探索了几种根据单元格值删除 Excel 中的行的方法。您可以选择您喜欢的一个。如果您有兴趣探索更多 Excel 提示和技巧,我们的网站提供了数千个教程,请 单击此处访问它们。 感谢您的阅读,我们期待在未来为您提供更多有用的信息!


相关文章:

  • 轻松删除 Excel 中的空白单元格 - 完整教程
  • 删除 Excel 中的空白单元格是一项常见任务,可以帮助简化数据,使其更易于分析、理解和呈现。空白单元格会扰乱您的数据分析,导致公式错误,并使您的数据集看起来不完整或不专业。在本教程中,我们将探索几种有效删除或管理 Excel 中的空白单元格的方法,例如“转到特殊功能”、公式、筛选功能。每种方法都满足不同的需求和场景,因此您可以选择最适合您的要求的方法。
  • 根据背景颜色删除行
  • 如何根据背景色删除整个行? 在此示例中,我需要删除所有单元格填充有蓝色背景色的所有行,如下面的屏幕截图所示。 通过本文,您将获得一些代码以在Excel中完成此任务。
  • 删除每隔一行
  • 如果要快速删除Excel中的所有其他行或列,重点是如何首先快速选择其他所有行或列,然后对它们应用删除操作。 本文将向您展示一些棘手的事情,有关如何首先选择每隔一行或每一列然后快速删除它们。
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