Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel宏以隐藏行_Excel_Vba - Fatal编程技术网

Excel宏以隐藏行

Excel宏以隐藏行,excel,vba,Excel,Vba,我不知道如何在Excel中编写宏,但我想我在你的网站上找到了一个答案,让我接近我所需要的。我的情况如下: If cell K23 = cell T20 then do nothing. If cell K23 = cell (T21:T23) then hide rows 25:65 以下是我目前掌握的宏: Sub HIDE() If Range(K23) = Range(T20) Then nil = True Else If Range(K23) = Range

我不知道如何在Excel中编写宏,但我想我在你的网站上找到了一个答案,让我接近我所需要的。我的情况如下:

If cell K23 = cell T20 then do nothing.  
If cell K23 = cell (T21:T23) then hide rows 25:65
以下是我目前掌握的宏:

Sub HIDE()
    If Range(K23) = Range(T20) Then nil = True
    Else
    If Range(K23) = Range("T21:T23") Then Rows("25:65").EntireRow.Hidden = True

    End If: End If:

End Sub
我得到一个错误,上面写着“没有If的Else”

请告诉我我做错了什么

谢谢。

你需要把“nil=true”放在另一行;如果要在与“if”相同的行上执行该语句,Excel VBA会将其视为“if”语句的结尾

所以你需要做:

Sub HIDE()
    If Range(K23) = Range(T20) Then 
        nil = True
    Else
        If Range(K23) = Range("T21:T23") Then 
            Rows("25:65").EntireRow.Hidden = True
        End If
    End If
End Sub
这样读起来也容易一些。正如对您的问题所作的评论,您需要提供更多的细节,以便我们帮助您让您的函数实际执行您需要它执行的操作。

单向

Sub tgr()

    Range("25:65").EntireRow.Hidden = (WorksheetFunction.CountIf(Range("T21:T23"), Range("K23").Text) > 0)

End Sub

第二个if需要澄清一下……如果K23等于T21:T23中的任何值或T21:T23中的所有值,或值的总和,是否要隐藏第25:65行。你能用文字写下你想发生的事吗?