Excel中的工作表更改[隐藏特定行] [英] Worksheet Change in Excel [Hiding Particular Rows]

查看:183
本文介绍了Excel中的工作表更改[隐藏特定行]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是文件的截图。

Here's the screenshot of the file.

我在VBA中使用以下代码来自动隐藏几行,一个特定的单元格

I am using the following code in VBA to hide few rows automatically with the change of values in a particular cell.

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim cell   As Range
    Set cell = Range("G1")
    If Not Application.Intersect(cell, Range(Target.Address)) Is Nothing Then
        If Range("G1").Value > 50 Then
            Rows("12:17").EntireRow.Hidden = False
        Else
            Rows("12:17").EntireRow.Hidden = True
        End If
    End If
End Sub

我已经将选项更改为宏启用。代码应该可以工作,但是没有到达。

I have changed options to macro enable. The code should work but it is not getting there.

推荐答案

在VBE中,点击[ctrl] + G 立即窗口并将其粘贴到应用程序.EnableEvents = True 然后在行尾输入。

In the VBE, tap [ctrl]+G to get to the Immediate window and paste this in Application.EnableEvents = True then hit enter at the end-of-line.

您的代码可以明显地修改为以下内容。 p>

You code can be appreciably trimmed down to the following.

Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("G1")) Is Nothing Then
        Rows("12:17").EntireRow.Hidden = CBool(Range("G1").Value <= 50)
    End If
End Sub

确保您处于工作表代码表中,而不是 ThisWorkbook 代码表或模块代码表。右键单击工作表的名称选项卡,然后选择查看代码是确保您位于正确位置的最快方法。

Make sure that you are in a worksheet code sheet and not the ThisWorkbook code sheet or a module code sheet. Right-clicking the worksheet's name tab and choosing View Code is the quickest way to make sure you are in the right place.

这篇关于Excel中的工作表更改[隐藏特定行]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆