vba - End If without Block if - 缩进,但仍然不起作用
问题描述
我经常收到错误“End If without Block If”,尽管我有一个 End if 作为开头 If 并且还尝试缩进语句。怎么了?
If TextBox1.Text = "" Then
MsgBox "Please Enter Value"
Else:
Sheets("confirmation").Range("F7").Value = ComboBox1.Value
Sheets("confirmation").Range("F9").Value = TextBox1.Value
For i = 20 To 1 Step -1
Rows(i & ":33").EntireRow.Hidden = False
Cells(13 + i, 1).Value = 20
i = i + 1
Exit For
UserForm1.Hide
End If
解决方案
去掉后面的冒号Else
。
替换Exit For
为Next
。Exit For
您可以提前退出 For 循环。
正如@Bill Hileman 在评论中提到的那样, For 循环将无限运行,因为i
在循环内递增,但在 For 循环体中递减。
If TextBox1.Text = "" Then
MsgBox "Please Enter Value"
Else
Sheets("confirmation").Range("F7").Value = ComboBox1.Value
Sheets("confirmation").Range("F9").Value = TextBox1.Value
For i = 20 To 1 Step -1
Rows(i & ":33").EntireRow.Hidden = False
Cells(13 + i, 1).Value = 20
i = i + 1
Next
UserForm1.Hide
End If
推荐阅读
- laravel - Laravel ErrorException 没有这样的文件或目录
- r - 在 R 中,如何删除其值全部为 FALSE 的列?
- laravel - 如何使用数据库中各自的值自动填充 Laravel Nova 操作字段?
- selenium - 有没有办法可以将桌面上的浏览器配置文件用作 Selenium 网络驱动程序?
- rust - 如何在引号内使用迭代器两次!宏?
- android - android studio 没有反映对应用程序的更改
- python - matplotlib 更改特定条的颜色
- sql - SQL 根据重量和代码的前 4 个字符显示可用库存
- java - 如何为 JSON 作业动态指定 ItemProcessor?
- json - 如何修改jackson jsonnode并在scala中写回漂亮的json