1

我不知道如何在 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

我收到一条错误消息“Else without If”

请告诉我我做错了什么。

谢谢。

4

2 回答 2

0

You need to put the "nil = true" on a separate line; if you have the statement to be executed on the same line as the "if", Excel VBA considers this to be the end of the "if" statement.

So you'd need to do:

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

It's also a little easier to read this way. As commented on your question, you'll need to provide a bit more detail in order for us to help you get your function actually doing exactly what you need it to do.

于 2013-08-21T13:56:09.113 回答
0

单程...

Sub tgr()

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

End Sub
于 2013-08-21T20:24:20.273 回答