跳到主要内容

如何在Excel中根据单元格值隐藏行?

假设您具有一定范围的数据,并且想基于列值隐藏行,例如,如果列的单元格值小于3000,则隐藏该单元格的行,如下面的屏幕快照所示。


在Excel中,可以使用“过滤器”功能根据单元格值过滤和隐藏行。

1.选择要过滤的数据,然后单击 时间 > 筛选器。 看截图:

doc根据值2隐藏行

2.然后单击向下箭头以显示过滤器下拉列表,然后单击 数字过滤器(或文本过滤器) > 比...更棒 (您可以从子菜单中选择所需的其他条件)。 看截图:

doc根据值3隐藏行

3.在弹出的对话框中,在大于大于旁边的文本框中键入条件。 看截图:

doc根据值4隐藏行

4。 点击 OK。 现在,仅显示大于3000的数据,并且隐藏数据小于3000的行。

doc根据值5隐藏行


此外,如果您对VBA代码感兴趣,在这里我可以介绍一个VBA代码以根据单元格值隐藏行。

1。 按 Alt + F11键 启用键 Microsoft Visual Basic应用程序 窗口。

2。 然后点击 插页 > 模块 打开一个新的 模块 窗口,然后将以下VBA代码粘贴到该窗口中。

VBA:根据单元格值隐藏行。

Sub HideRow()
'Updateby20150618
Dim Rng As Range
Dim WorkRng As Range
Dim xNumber As Integer
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
xNumber = Application.InputBox("Number", xTitleId, "", Type:=1)
For Each Rng In WorkRng
    Rng.EntireRow.Hidden = Rng.Value < xNumber
Next
End Sub

3.然后按 F5 键来运行VBA,然后在弹出对话框中选择要隐藏行的数据范围(标题除外)。 看截图:

doc根据值6隐藏行

4。 点击 OK,然后在第二个对话框中输入标准编号。 看截图:

doc根据值7隐藏行

5。 点击 OK。 现在,其数据小于3000的行被隐藏。

提示: 如果要隐藏大于3000的行,只需更改 Rng.EntireRow.Hidden = Rng.Value <xNumberRng.EntireRow.Hidden = Rng.Value> xNumber,或者如果您要隐藏数据等于3000的行,请更改为 Rng.EntireRow.Hidden = Rng.Value = xNumber.


根据Excel中的条件快速选择单元格

使用 Kutools for Excel 的 选择特定的单元格,您可以一次根据一两个条件选择单元格。 
doc选择特定的单元格
 
Kutools for Excel:拥有300多个便捷的Excel加载项,可以在30天内免费试用。

如果您既不想对VBA启用过滤器功能,也不想对VBA启用过滤器功能,那么在这里我为您介绍一个方便的工具- 选择特定的单元格 of Kutools for Excel 要根据单元格值快速选择整个行,则可以将其隐藏。

Kutools for Excel, 与超过 300 方便的功能,使您的工作更加轻松。 

免费安装 Kutools for Excel,请执行以下操作:

小费。 如果您想免费试用“提取文字”功能, 请去免费试用 Kutools for Excel 首先,然后按照上述步骤进行操作。

1.选择数据范围,然后单击 库工具 > 选择 > 选择特定的单元格。 看截图:

doc根据值14隐藏行

2.在 选择特定的单元格 对话框,检查 整行 选择类型 部分,然后从中选择所需的条件 特定类型 列表,然后在文本框中键入数字或文本。 看截图:

doc根据值9隐藏行

3。 点击 Ok > OK 关闭对话框。 现在,选择了数据小于3000的行,您只需要右键单击行标题以显示上下文菜单,然后单击“隐藏”。 看截图:
doc根据值10隐藏行

现在,其数据小于3000的行被隐藏。

doc根据值11隐藏行

提示:

1.如果要隐藏包含特定值的行,则可以选择 包含 然后在文本框中输入特定值。

doc根据值12隐藏行

2.如果要隐藏包含大于或小于值的行,则可以选择 比...更棒小于,然后在两个框中键入值,然后检查 .

doc根据值13隐藏行

使用 Kutools for Excel 选择特定的单元格 实用程序,您可以识别特定单元格的位置,根据单元格值选择整个行或列,等等。 单击此处了解有关此实用程序的更多信息。

Kutools for Excel:Excel 中必须具备的 300 多个函数, 从这里免费试用30天。

最佳办公生产力工具

🤖 Kutools 人工智能助手:基于以下内容彻底改变数据分析: 智能执行   |  生成代码  |  创建自定义公式  |  分析数据并生成图表  |  调用 Kutools 函数...
热门特色: 查找、突出显示或识别重复项   |  删除空白行   |  合并列或单元格而不丢失数据   |   不使用公式进行四舍五入 ...
超级查询: 多条件VLookup    多值VLookup  |   跨多个工作表的 VLookup   |   模糊查询 ....
高级下拉列表: 快速创建下拉列表   |  依赖下拉列表   |  多选下拉列表 ....
列管理器: 添加特定数量的列  |  移动列  |  切换隐藏列的可见性状态  |  比较范围和列 ...
特色功能: 网格焦点   |  设计图   |   大方程式酒吧    工作簿和工作表管理器   |  资源库 (自动文本)   |  日期选择器   |  合并工作表   |  加密/解密单元格    按列表发送电子邮件   |  超级筛选   |   特殊过滤器 (过滤粗体/斜体/删除线...)...
前 15 个工具集12 文本 工具 (添加文本, 删除字符,...)   |   50+ 图表 类型 (甘特图,...)   |   40+ 实用 公式 (根据生日计算年龄,...)   |   19 插入 工具 (插入二维码, 从路径插入图片,...)   |   12 转化 工具 (小写金额转大写, 货币兑换,...)   |   7 合并与拆分 工具 (高级组合行, 分裂细胞,...)   |   ... 和更多

使用 Kutools for Excel 增强您的 Excel 技能,体验前所未有的效率。 Kutools for Excel 提供了 300 多种高级功能来提高生产力并节省时间。  单击此处获取您最需要的功能...

产品描述


Office Tab 为 Office 带来选项卡式界面,让您的工作更加轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,发布者,Access,Visio和Project。
  • 在同一窗口的新选项卡中而不是在新窗口中打开并创建多个文档。
  • 每天将您的工作效率提高50%,并减少数百次鼠标单击!
Comments (17)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Yes, "Entire Row" is selected.
This comment was minimized by the moderator on the site
All rows remain selected without using Kutools. As soon as I use Kutools and select header row, all other rows but the header row de-select.
This comment was minimized by the moderator on the site
Are you sure check the Entire row option in the dialog? If you check cell option, the selected cells will be unselected when you right click at one row.
https://www.extendoffice.com/images/stories/comments/sun-comment/doc-select-specific-cell-1.png
This comment was minimized by the moderator on the site
Hi - I'm using a newer Lenovo PC with Windows 10 Professional and Microsoft 365 Apps for business. Excel Version 2210 (Build 15726.20202 Click-to-Run).
This comment was minimized by the moderator on the site
I have tried the operation in the same version with you, there is no any problem. Could you try to manually select several rows (without using Kutools for Excel), then right click at one row header, see all rows are remained selecting?
This comment was minimized by the moderator on the site
I have done exactly what you've demonstrated. However, when I right-click on the row header, all other rows become de-selected and only that one row remains selected to be hidden or deleted. No matter what I do, the other rows do not stay selected when right-clicking on the header. I'm at a loss to know what to do now.
This comment was minimized by the moderator on the site
I am so sorry for that. Could you tell me what Excel version and system you use?
This comment was minimized by the moderator on the site
Hello,

That is exactly what I've been doing, however, it only hides the row on which I have clicked the row header. All other selected rows remain unhidden, and are deselected at the same time. I will try it again following your gif exactly. Thanks for your reply.
This comment was minimized by the moderator on the site
I'm using Kutools to select entire rows based on a value, and it does select all the rows with that value. However, when I right-click on the row header and click on "Hide" in the menu, only that row is hidden and the rest that were selected become de-selected. It appears I still have to hide each row one at a time. What am I doing wrong?
This comment was minimized by the moderator on the site
Hi, Rochelley, I think there may be some wrong when you right-click at the row header. After the rows which match your condition are selecetd after applying the feature, right click at one row header of them, note that other rows are kept selected, then choose hide from the context menu. Please see the gif:
https://www.extendoffice.com/images/stories/comments/sun-comment/doc-hide-selected-row.gif
This comment was minimized by the moderator on the site
Hello,

I have a drop down with multiple reponses. I am trying to hide certain rows dependant on the response, can someone please assist?

Dropdown options are "CDI", "AR", "Legal", "Multiple" and "Other".

If response is CDI then hide rows 42-100

If response is AR then hide rows 19-41 and rows 66-100

If response is Legal then hide rows 19-66 and rows 88-100

If response is multiple then don't hide anything

If response is Other then hide rows 19-88



Can someone please asssist?
This comment was minimized by the moderator on the site
Hi I need some help with my work sheet. I have to build a dynamic questionnaire and I need to have a code that allow me to hide/ Unhide automatically some rows base on a cell information. Example:

if c6 is "internally" then show me row 7 but hide 8 to 107
if c6 is "Externally" then hide all the rows from 7 to 107


if c7 is "yes" then show me row 8 but hide 9 to 107
if c7 is "No" then show me row 8 but hide 9 to 107
if c8 is "Critical" then show me row 9 but hide 10 to 107

if c8 is "Important" show me row 9 but hide 10 to 107
if c8 is "Ordinary" show me row 9 but hide 10 to 107
if c8 is "Other" then show me row 9 but hide 10 to 107

if c9 is "Critical" then show me row 10 but hide 11 to 107
if c9 is "Important" then show me row 10 but hide 11 to 107
if c9 is "Ordinary" then show me row 10 but hide 11 to 107
if c9 is "Other" then show me row 10 but hide 11 to 107

etc.

can somebody help me?
This comment was minimized by the moderator on the site
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 And Target.Row = 1 Then

If Target.Value = "YES" Then
Worksheets(2).Activate
Worksheets(2).Application.Columns("A:Z").Select
Worksheets(2).Application.Selection.EntireColumn.Hidden = True
Worksheets(2).Application.Columns("AA:AZ").Select
Worksheets(2).Application.Selection.EntireColumn.Hidden = False
ElseIf Target.Value = "NO" Then
Worksheets(2).Activate
Worksheets(2).Application.Columns("AA:AZ").Select
Worksheets(2).Application.Selection.EntireColumn.Hidden = True
Worksheets(2).Application.Columns("A:Z").Select
Worksheets(2).Application.Selection.EntireColumn.Hidden = False
Else
Worksheets(2).Activate
Worksheets(2).Application.Columns("A:Z").Select
Worksheets(2).Application.Selection.EntireColumn.Hidden = False
Worksheets(2).Application.Columns("AA:AZ").Select
Worksheets(2).Application.Selection.EntireColumn.Hidden = False
End If

End If
End Sub
This comment was minimized by the moderator on the site
I got same error
This comment was minimized by the moderator on the site
Sorry I do not know either.
This comment was minimized by the moderator on the site
I don't know either Sunny
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