用于在Excel VBA中隐藏/显示行的if语句 [英] If statement to hide/show rows in Excel VBA

查看:366
本文介绍了用于在Excel VBA中隐藏/显示行的if语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个代码序列,如果C37为空白,我希望隐藏两行行.为此,我拥有的代码可以成功工作.

I have a sequence of code where if C37 is blank, I want two series of rows to be hidden. The code I have works successfully for this.

但是,

如果D37不是空白,我希望隐藏同一系列的行.

If D37 is not blank I would like the same series of rows to be unhidden.

'Show/Hide Filter Index Columns

If Worksheets("Req Sheet").Range("C37").Value = "" Then
   Worksheets("Formulation").Rows("54:57").EntireRow.Hidden = True
   Worksheets("Formulation").Rows("125:128").EntireRow.Hidden = True
Else
    Rows("54:57").EntireRow.Hidden = False
    Rows("125:128").EntireRow.Hidden = False

End If

If Worksheets("Req Sheet").Range("C38").Value = "" Then
   Worksheets("Formulation").Rows("54:57").EntireRow.Hidden = True
   Worksheets("Formulation").Rows("125:128").EntireRow.Hidden = True
Else
    Rows("54:57").EntireRow.Hidden = False
    Rows("125:128").EntireRow.Hidden = False

End If

我知道我的代码语法错误,但是我遇到的问题是C38中的第二部分代码将取代C37中的代码.

I know I have the syntax of the code wrong, but the problem I am getting is that the second portion of code from C38 will supersede the code from the from C37.

我尝试使用and运算符,但无法成功!

I have tried using an and operator but I couldn't achieve success!

感谢您的帮助!

推荐答案

With Worksheets("Req Sheet")

    If .Range("C37").Value <> "" Or .Range("C38").Value <> "" Then
        Worksheets("Formulation").Rows("54:57").EntireRow.Hidden = False
        Worksheets("Formulation").Rows("125:128").EntireRow.Hidden = False
    Else
        Worksheets("Formulation").Rows("54:57").EntireRow.Hidden = True
        Worksheets("Formulation").Rows("125:128").EntireRow.Hidden = True

        Rows("54:57").EntireRow.Hidden = False
        Rows("125:128").EntireRow.Hidden = False
    End If

End With

这篇关于用于在Excel VBA中隐藏/显示行的if语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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