我已经阅读了一些关于在Excel中隐藏行的帖子,他们都帮我隐藏了,但我似乎还没有找到任何解决方案,为什么它不会UNHIDE。
我使用以下代码:
Private Sub Worksheet_Calculate() Dim LastRow As Long, c As Range Application.EnableEvents = False LastRow = Cells(Cells.Rows.Count, "D").End(xlUp).Row On Error Resume Next For Each c In Range("D116:D" & LastRow) If c.Value = 0 Then c.EntireRow.Hidden = True ElseIf c.Value > 0 Then c.EntireRow.Hidden = False End If Next On Error GoTo 0 Application.EnableEvents = True End Sub如果我从一些1和一些0值开始,那么代码会成功隐藏值为0的行,并且还会继续处于活动状态,从而确保我稍后从1更改为0的任何值都会自动隐藏。
但是,最初为0的值(一旦更改为1)将不会自动取消UNHIDE。 这是一个很大的问题,因为我打算从所有零值开始,然后在这些值变为1或大于1时取消隐藏行。值得注意的是,D列中的这些值是对同一电子表格中其他位置的引用(只是例如= N100),这样即使隐藏行也可以控制值。 我不认为使用公式是一个问题,因为它仍然可以响应HIDE的动态变化(当从1变为0时),而不是UNHIDE。
有什么建议么?
I have read a number of posts about hiding rows in Excel, and they all helped me with the hiding, but I still don't seem to find any solutions for why it will not UNHIDE.
I am using the following code:
Private Sub Worksheet_Calculate() Dim LastRow As Long, c As Range Application.EnableEvents = False LastRow = Cells(Cells.Rows.Count, "D").End(xlUp).Row On Error Resume Next For Each c In Range("D116:D" & LastRow) If c.Value = 0 Then c.EntireRow.Hidden = True ElseIf c.Value > 0 Then c.EntireRow.Hidden = False End If Next On Error GoTo 0 Application.EnableEvents = True End SubIf I start with some 1 and some 0 values, then the code successfully hides the rows with value 0, AND also continues to be active, ensuring that any values I later change from 1 to 0 are automatically hidden.
However, the values that were initially 0, once changed to 1, will not UNHIDE automatically. This is a big problem because I intend to start with all zero values, and then unhide rows as these values change to 1 or greater than 1. It's worth of note that these values in column D are references to somewhere else in the same spreadsheet (just for instance =N100), so that I can control the values even when the rows are hidden. I didn't think the use of a formula was a problem because it can still respond to dynamic changes to HIDE (when changed from 1 to 0), just not to UNHIDE.
Any suggestions?
最满意答案
我不确定如何在VBA中显示一行,你看起来正确显示一行。 但是当我不确定如何做某事时,我会记录一个宏来做我想要实现的事情,然后只查看excel生成的代码。
I'm not sure exactly how to show a row in VBA, what you have looks right to show a row. But when I was ever unsure how to do something, I would record a macro to do what I wanted to achieve and then just review the code that excel generates.
更多推荐
发布评论