开发者

Getting For Without Next Error, not sure why

I'm trying to loop throw rows and say "if the cell in this column begins with 49, hide the entire row". Here's my code:

For i = 2 To LastRow
    If Rows("AK" & i).Value Like "49*" Then
        Rows("AK" & i).EntireRow.Hidden = True
Next i

It keeps stopping on the last line and saying "For without next". Can it not see the FOR line three lines up? This is just one of many stat开发者_如何学运维ements I have like this but I think fixing this one will help me format the others. What am I doing wrong?


Your missing an End If (The wording is like that because It sees a Next within an If block without a matching For; which is illegal)

For i = 2 To LastRow
    If Range("AK" & i).Value Like "49*" Then
        Range("AK" & i).EntireRow.Hidden = True
    End If
Next i


End if is missing !
It is required if you put the next instruction on another line.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜