热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

VBA7.0:for循环中GoTo上的编译器错误-VBA7.0:CompilererroronGoToinsideaforloop

Iamtryingtocontinuetheforloopintheifconditionbelow,butVBAcomplainscompileerror:Ne

I am trying to continue the for loop in the if condition below, but VBA complains compile error: "Next without For".
I am using "GoTo", because there is no "continue" keyword in VBA, such as other typical programming languages.

我试图在下面的if条件中继续for循环,但是VBA抱怨编译错误:“Next without For”。我正在使用“GoTo”,因为VBA中没有“continue”关键字,例如其他典型的编程语言。

Any idea what is wrong here?

知道这里有什么问题吗?

For RowIndex = 2 To lastrow

    If Worksheets("Sheet1").Range("$b$" & RowIndex) = "" Then
      GoTo EndLoop

    output_string = setproperty & Worksheets("Sheet1").Range("$b$" & RowIndex) & " [ get_ports " & """" & Worksheets("Sheet1").Range("$g$" & RowIndex) & """" & " ]"
    Print #1, output_string

    output_string = setpropertyiostandard & Worksheets("Sheet1").Range("$k$" & RowIndex) & " [ get_ports """ & Worksheets("Sheet1").Range("$g$" & RowIndex) & """" & " ]"
    Print #1, output_string


    If Worksheets("Sheet1").Range("$k$" & RowIndex) = "LVCMOS18" Then
        'Debug.Print "found" & RowIndex
        output_string = "set_property DRIVE 8 [ get_ports " & Worksheets("Sheet1").Range("$g$" & RowIndex) & "]"
        Print #1, output_string
    End If

EndLoop:
Next RowIndex

2 个解决方案

#1


3  

Your first If/Then is left open, need to close that up within the for loop.

你的第一个If / Then保持打开状态,需要在for循环中关闭它。

#2


0  

In your case you can change the test from = to <>. Another trick is to use while true loop

在您的情况下,您可以将测试从=更改为<>。另一个技巧是使用while循环

For RowIndex = 2 to LastRow
  While true
    If Worksheets("Sheet1").Range("$b$" & RowIndex) = "" Then Exit Do

    Rest of your code here

    Exit Do '<- Remember to do this or you'll be caught in an infinite loop
  Loop
Next

推荐阅读
author-avatar
壹花壹浄土
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有