作者Catbert (宅男)
看板Visual_Basic
标题Re: [VBA ] FOR-next 可有指令跳下一个?
时间Fri Dec 16 07:22:15 2011
※ 引述《lytn (sapphira)》之铭言:
: 想问一下
: For i = x to y
: A(i)
: B(i)
: C(i)
: next
: 以上结构,如果是需要ABC都跑完是OK的
: 如果是有时候只要跑到A 或 B 即完成,有没有预设的指定可以做到?
: 我以前是用巢状IF一层一层去包,但是又很烦
: 有没有其他作法可以分享呢?
是要跳下一个i还是要跳出回圈??
如果是要跳出回圈,那用Exit For
如果是要跳下一个i,在Excel VBA只能用GoTo
例如
For i = x to y
if A(i)=m then
GoTo Continue1
elseif A(i) =n then
Exit For
end if
if B(i)=m then
GoTo Continue1
elseif B(i) =n then
Exit For
end if
if C(i)=m then
GoTo Continue1
elseif C(i) =n then
Exit For
end if
Continue1:
Next
--
I am a phantom.
I existed on people's need.
When nobody needs me anymore,
I would disappear.
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 175.180.135.78
1F:推 Marty:原PO似乎是要问除了用if去包以外的方法...不过应该是很难.. 12/16 08:08
2F:→ MOONRAKER:我觉得他是需要相当於C的continue的东东。在VBA的确是只 12/16 11:02
3F:→ MOONRAKER:能用goto或用if包住,即使do...loop也只能这样弄。 12/16 11:04
4F:推 lytn:感谢详细说明 12/17 14:24