excel - 退出 If 和 Next For
问题描述
我有一个带有 if 语句的 for next 循环。如果“If 语句”为真,则退出 if 和 next for。这是代码:我想要的是如果 Rng1 不在 Range1 中,那么转到下一个 rng1。我似乎是一个简单的解决方案,但我无法弄清楚。先感谢您。
Sub me_test()
Dim Range1 As Range
Dim Rng1 As Range
Set Range1 = Application.Selection
Set Range1 = Application.InputBox("Please Select Your Range :", xtitledID, Range1.Address, Type:=8)
For Each Rng1 In Range1
If Intersect(Rng1, Range("B7:B15")) Is Nothing Then
MsgBox "Not within the perscribed range." & vbCr & "Please click OK to continue."
Else
Rng1.Value = "Good"
End If
Next
MsgBox "All Done"
End Sub
解决方案
Sub me_test()
Dim Range1 As Range
Dim Rng1 As Range
Set Range1 = Application.Selection
Set Range1 = Application.InputBox("Please Select Your Range :", xtitledID, _
Range1.Address, Type:=8)
Set Range1 = Application.Intersect(Range1, ActiveSheet.Range("B7:B15"))
If Range1 is nothing then
MsgBox "No valid cells selected!"
else
Range1.Value = "Good"
end if
End Sub
推荐阅读
- javascript - 在 InfluxDB API 中支持应用程序/json 主体的 Influx 1.8.3
- powershell - 如何选择非空 CSV 单元格并将它们放入 Powershell 中的数组中?
- passport-jwt - 替代user.findone?
- java - 在命令行中打印的异步流
- python - 训练测试拆分句子列表
- python - 追加一个列表和一个元组作为一个列表一起列出
- html - 如何将按钮固定在内部班级?
- reporting-services - SQL SSRS,表达式 iif 总和未按预期计算
- vue.js - 在 Vuex Store 中获取未知的本地操作类型
- google-apps-script - 在共享驱动器中查找和替换功能多个文档