根据单元格内容快速删除行,首先需要选中含有该单元格内容的所有行,然后删除。似乎在 Excel 当中除了 VBA 以外没有其他更快捷的方法能解决这个问题了。这里将推荐几个快速根据单元格内容删除行的方法给你。
用 Kutools for Excel 删除含有特定单元格内容的行
通过查找和替换删除含有特定单元格内容的行
在 Excel 当中,查找和替换功能是非常强大有用的,它也可以用来根据某个特定值删除行。
1. 按住 Ctrl + F 打开查找和替换对话框,然后在查找内容文本框里输入苹果(苹果就是你想要删除的行所依据的值)。如图所示:
2. 点击查找全部, 然后按 Ctrl + A 选中所有找到的结果。如图所示:
3. 点击关闭,你就会看到所有含有苹果的单元格都被选中了。右键点击打开右键菜单,选择删除。 如图所示:
4. 在删除对话框当中,选择整行。
通过 VBA 代码删除含有特定单元格内容的行
用 VBA 代码快速删除包含特定值的行,可以按照以下步骤来实现:
Kutools for Excel: 囊括了120多種快速提升您 Excel 使用效率的工具。 60天內免費试用。. |
1. 选中想要删除行的区域。
2. 按住 Alt+ F11 打开 Microsoft Visual Basic for applications 窗口,然后点击插入 >> 模块,将下面代码复制粘贴到模块窗口当中。
VBA 代码: 根据指定单元格内容删除行
Sub DeleteRows()
'Updateby20140314
Dim rng As Range
Dim InputRng As Range
Dim DeleteRng As Range
Dim DeleteStr As String
xTitleId = "KutoolsforExcel"
Set InputRng = Application.Selection
Set InputRng = Application.InputBox("Range :", xTitleId, InputRng.Address, Type:=8)
DeleteStr = Application.InputBox("Delete Text", xTitleId, Type:=2)
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)
End If
End If
Next
DeleteRng.EntireRow.Delete
End Sub
3. 点击 F5 运行代码,在弹出的窗口中选择需要应用代码的区域。
4. 点击确定,会弹出另外一个窗口让你选择所依据的单元格,如图所示:
5. 点击确定,含有苹果的行就被删除了。
但是对于 Excel 初学者而言,通过 VBA 代码就有点复杂。所以接下来介绍一个更简单易懂的方法来依据单元格值删除行。
用 Kutools For Excel 删除含有特定单元格内容的行
如果你已经安装了 Kutools for Excel,通过它的选择指定单元格功能可快速地根据某个特定值删除行。
Kutools for Excel: 囊括了120多种快速提升您 Excel 使用效率的工具。60天內免费试用。. |
1. 选中需要根据单元格内容删除行的区域。
2. 点击 Kutools >> 选择 >> 选择指定单元格。如图所示:
3. 在选择指定单元格对话框当中,在选择类型中选择整行,然后在指定类型区域选择等于,并在旁边的文本框当中输入你想要依据的值(苹果)。 如图所示:
4. 点击确定或者应用,所有单元格值为苹果所在的行都被选中了。
注意:点击确定以后会弹出一个对话框告诉你有多少行被选中了。
5. 右键点击选中的行,在右键菜单中点击删除,所有含有苹果这一指定单元格内容的行将被删除。
Is Your Problem Solved?
Yes, I want to be more efficiency and save time when using Excel No, the problem persists and I need further support
Recommended Productivity Tools
The following tools will greatly save your time and effort, which one do you prefer?
Office Tab: Using handy tabs in your Office, as the way of Chrome, Firefox and New Internet Explorer.
Kutools for Excel: 120 powerful new functions for Excel, Increase your productivity in 5 minutes. Save two hours every day!
Classic Menu for Office: Bring back familiar menus to Office 2007, 2010, 2013, 2016, 2019 and 365, as if it were Office 2000 and 2003.
Kutools For Excel
Amazing! Increase your productivity in 5 minutes. Don't need any special skills, save two hours every day!
More than 200 powerful advanced functions which designed for Excel:
- Merge Cell/Rows/Columns without Losing Data.
- Combine and Consolidate Multiple Sheets and Workbooks.
- Compare Ranges, Copy Multiple Ranges, Convert Text to Date, Unit and Currency Conversion.
- Count by Colors, Paging Subtotals, Advanced Sort and Super Filter,
- More Select/Insert/Delete/Text/Format/Link/Comment/Workbooks/Worksheets Tools...