在编写VBA条件过程中我想大多人多首选IF来执行!但是你先看看IF语句的代码!
- If Range("A1") >=90 Then
- Msgbox "You got an A on the test!"
- ElseIf Range("A1") <90 And Range("A1") >=80 Then
- Msgbox "You got a B on the test"
- ElseIf Range("A1") <80 And Range("A1") >=70 Then
- Msgbox "You got a C on the test"
- ElseIf Range("A1") < 70 And Range("A1") >=60 Then
- Msgbox "You got a D on the test"
- Else
- Msgbox "You failed"
- End If
再来看看select case的语句:
- Select Case Range("A1")
- Case A1 >=90
- Msgbox "You got an A on the test"
- Case 80 To 89
- Msgbox "You got a B on the test"
- Case 70 To 79
- Msgbox "You got a C on the test"
- Case 60 To 69
- Msgbox "You got a D on the test"
- Case Else
- Msgbox "You failed"
- End Select
仔细看看2个代码所追求的目的是一样的!但是2个总体结构还是Select Case简洁,我们写代码无非就是追求简洁便于阅读!
学习下吧!Select Case效果未必比IF差!
又是代码呀~~~
呵呵!excel开发当然是代码为主了!
恩,还是select case好
呵呵!你发现了!
新手学习了!强大的博主
过奖,有空常来
我看不出来有什么区别
代码的结构明细就很明显啊!