excel - 是否可以在其中更新 For End 参数?
问题描述
我想在 For 内部更改我的 For "End" 参数。
例如:
ForEnd = 3
for i = 1 To ForEnd
If Something = "TRUE" Then
ForEnd = ForEnd + 1
End If
Next i
这不起作用,因为一旦代码通过第一行,就会定义“结束”或“上限”参数。即使我在代码中更改它,它也会考虑原始值。
有什么想法吗?
谢谢你。
解决方案
正如 Olff 所说,将 for 循环替换为 while 循环:
ForEnd = 3
i = 1
while i<ForEnd
If Something = "TRUE" Then
ForEnd = ForEnd + 1
End If
i = i + 1
Wend
小心不要陷入无限循环!(Something
需要不同于"TRUE"
常规)
另一种方法(更现代的方法)是使用以下Do..Loop
方法:
ForEnd = 3
i = 1
Do While i<ForEnd
If Something = "TRUE" Then
ForEnd = ForEnd + 1
End If
i = i + 1
Loop
推荐阅读
- python - “用户警告:Matplotlib 当前使用的是 agg,这是一个非 GUI 后端,因此无法显示该图。” 在 Pycharm 上用 pyplot 绘制图形时
- r - 如何将反斜杠替换为 R 中整个 CSV 文件的正斜杠?
- json - React 认为我的“AbstractContract”是一个“对象”并且在我调用方法时不会呈现
- python - 为每个 Pandas 单元格设置相同的字典
- javascript - 在 Javascript 中从非关系数据库构建 JSON 树时遇到问题
- python - 从图形 Python 程序中使用 sudo 运行命令
- linux - 我可以从 Yocto 配方为尚不存在的文件创建符号链接吗
- ios - 如何修复我的主故事板上不正确的(小)视图
- nhibernate - NHibernate QueryOver 并选择属性为 ILIST 且列表计数 >= 1 的行
- d3.js - 需要将散点图与雷达图混合以绘制高尔夫击球 - 在 D3 中可能吗?包含示例图片