[VBA ]錯誤跳過(on error resume next);那錯誤不跳過重來執行一遍?

看板Visual_Basic作者 (swallow)時間19年前 (2006/07/08 22:02), 編輯推噓3(302)
留言5則, 3人參與, 最新討論串1/1
錯誤跳過的指令是:on error resume next; 那錯誤不跳過重來執行一遍要如何寫 假設錯誤則跳過 sub test() for i = 1 to 700 on error resume next cells(i,1)=time application.ontime now + timevalue("00:00:01"),"thisworkbook.exeself" next end sub 假設i=400時發生問題 則跳過;執行i=401 如果我不想跳過的話要如何寫 我想要發生錯誤時再重來執行一遍;就是我一定要執行成功 我的想法是 sub test() for i = 1 to 700 if error then i=400 '我亂寫 ,因為我不會 cells(i,1)=time application.ontime now + timevalue("00:00:01"),"thisworkbook.exeself" endif next end sub 以上例子只是我舉例而已 請各位高手不吝賜教 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.131.65.134

07/08 22:31, , 1F
如果我寫 on error goto 0 則i會從1或者400重新執行?
07/08 22:31, 1F

07/08 22:53, , 2F
公司規定不能用goto所以我會寫if err.number<>0 then...
07/08 22:53, 2F

07/08 22:55, , 3F
goto 0是取消on error...
07/08 22:55, 3F

07/08 22:55, , 4F

07/12 14:08, , 5F
我會了 謝謝各位幫忙
07/12 14:08, 5F
文章代碼(AID): #14hxiBTn (Visual_Basic)
文章代碼(AID): #14hxiBTn (Visual_Basic)