vba 没有下一个错误,不知道为什么
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6426295/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting For Without Next Error, not sure why
提问by Mr_Thomas
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:
我试图循环抛出行并说“如果此列中的单元格以 49 开头,则隐藏整行”。这是我的代码:
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 statements I have like this but I think fixing this one will help me format the others. What am I doing wrong?
它一直停在最后一行并说“没有下一个”。看不到 FOR 行三行吗?这只是我喜欢的众多声明之一,但我认为修复这个将帮助我格式化其他声明。我究竟做错了什么?
回答by Alex K.
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)
您缺少 an End If
(措辞是这样的,因为它Next
在If
没有匹配的块中看到 a For
;这是非法的)
For i = 2 To LastRow
If Range("AK" & i).Value Like "49*" Then
Range("AK" & i).EntireRow.Hidden = True
End If
Next i
回答by Patrick Honorez
End if is missing !
It is required if you put the next instruction on another line.
缺少就结束!
如果您将下一条指令放在另一行,则它是必需的。