VBA代码:隐藏但不会取消隐藏行(VBA codes: hides but won't unhide rows)

编程入门 行业动态 更新时间:2024-10-21 05:46:27
VBA代码:隐藏但不会取消隐藏行(VBA codes: hides but won't unhide rows)

我已经阅读了一些关于在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 Sub

If 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.

更多推荐

本文发布于:2023-07-23 18:41:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1235674.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:代码   codes   VBA   rows   unhide

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!