小编Sat*_*ish的帖子

哪个是最佳使用:嵌套if语句或单个if语句在VBA中具有多个"AND"条件?

我正在为VBA中的MS Excel编写一个宏.在子程序中,我有一组条件要满足要执行的特定任务.从运行时间和内存的角度来看,下列哪种方法最佳?

方法1:

If condition_1 then
  If condition_2 then
     If condition_3 then
       ....
     End If
  End If
End If
Run Code Online (Sandbox Code Playgroud)

要么

方法2:

If condition_1 And condition_2 And ..... then
  ....
End If
Run Code Online (Sandbox Code Playgroud)

如果我有任何条件的Else语句,我必须去方法1来实现它.但是我没有任何条件的Else声明,因此两种方法在完成任务时都处于相同的水平.我只是想知道哪一个在运行时和内存方面会更好?

excel vba if-statement excel-vba

2
推荐指数
1
解决办法
395
查看次数

标签 统计

excel ×1

excel-vba ×1

if-statement ×1

vba ×1