brothertruffle880
asked on
VBA Excel Question: If then Else VERSUS select case
Are the "If then else" and "Select Case" interchangable? It seems that they can both be used in the same applications. Or are one of them more appropriate/efficient/etc. at some tasks?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Select Case can be a lot easier to write. For example
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -
My Articles:
Using the VB6 Debugger • Automatic Insertion of Procedure Names
A Textbox ActiveX Control That Limits Input to Numbers • Spell Check a Textbox
Improved Formatting Tags • Conditional Compilation
Marty - MVP 2009, 2010, 2011
If x = 1 or x = 5 or x = 12 or x > 20 Then…
'do something
compared to Select Case x
Case 1, 5, 12, > 20
'do something
--------------------------
My Articles:
Using the VB6 Debugger • Automatic Insertion of Procedure Names
A Textbox ActiveX Control That Limits Input to Numbers • Spell Check a Textbox
Improved Formatting Tags • Conditional Compilation
Marty - MVP 2009, 2010, 2011
If (ElseIf) End If can work with multiple values and use logical expressions/operators, but can be difficult to follow.