You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 14, 2024. It is now read-only.
Copy file name to clipboardExpand all lines: VBA/Language-Reference-VBA/articles/select-case-statement.md
+12-7Lines changed: 12 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -15,25 +15,30 @@ Executes one of several groups of [statements](vbe-glossary.md), depending on th
15
15
16
16
**Syntax**
17
17
18
-
**Select Case**_testexpression_
19
-
[**Case**_expressionlist-n_
18
+
**Select Case**_testexpression_
19
+
[**Case**_expressionlist-n_
20
20
[_statements-n_]]
21
21
[**Case Else**
22
22
[_elsestatements_]]
23
23
24
24
**End Select**
25
+
25
26
The **Select Case** statement syntax has these parts:
26
27
27
28
28
29
|**Part**|**Description**|
29
30
|:-----|:-----|
30
31
|_testexpression_|Required. Any [numeric expression](vbe-glossary.md) or[string expression](vbe-glossary.md).|
31
-
|_expressionlist-n_|Required if a **Case** appears. Delimited list of one or more of the following forms: _expression_, _expression_**To**_expression_, **Is**_comparisonoperator__expression_. The **To**[keyword](vbe-glossary.md) specifies a range of values. If you use the **To** keyword, the smaller value must appear before **To**. Use the **Is** keyword with[comparison operators](vbe-glossary.md) (except **Is** and **Like**) to specify a range of values. If not supplied, the **Is** keyword is automatically inserted.|
32
+
|_expressionlist-n_|Required if a **Case** appears. Delimited list of one or more of the following forms: _expression_, _expression_**To**_expression_, **Is**_comparisonoperator__expression_. The **To**[keyword](vbe-glossary.md) specifies a range of values. If you use the **To** keyword, the smaller value must appear before **To**. Use the **Is** keyword with[comparison operators](vbe-glossary.md) (except **Is** and **Like**) to specify a range of values. If not supplied, the **Is** keyword is automatically inserted.|
32
33
|_statements-n_|Optional. One or more statements executed if _testexpression_ matches any part of _expressionlist-n._|
33
34
|_elsestatements_|Optional. One or more statements executed if _testexpression_ doesn't match any of the **Case** clause.|
34
-
**Remarks**
35
-
If _testexpression_ matches any **Case**_expressionlist_ expression, the _statements_ following that **Case** clause are executed up to the next **Case** clause, or, for the last clause, up to **End Select**. Control then passes to the statement following **End Select**. If _testexpression_ matches an _expressionlist_ expression in more than one **Case** clause, only the statements following the first match are executed.
36
-
The **Case Else** clause is used to indicate the _elsestatements_ to be executed if no match is found between the _testexpression_ and an _expressionlist_ in any of the other **Case** selections. Although not required, it is a good idea to have a **Case Else** statement in your **Select Case** block to handle unforeseen _testexpression_ values. If no **Case**_expressionlist_ matches _testexpression_ and there is no **Case Else** statement, execution continues at the statement following **End Select**.
35
+
36
+
**Remarks**
37
+
38
+
If _testexpression_ matches any **Case**_expressionlist_ expression, the _statements_ following that **Case** clause are executed up to the next **Case** clause, or, for the last clause, up to **End Select**. Control then passes to the statement following **End Select**. If _testexpression_ matches an _expressionlist_ expression in more than one **Case** clause, only the statements following the first match are executed.
39
+
40
+
The **Case Else** clause is used to indicate the _elsestatements_ to be executed if no match is found between the _testexpression_ and an _expressionlist_ in any of the other **Case** selections. Although not required, it is a good idea to have a **Case Else** statement in your **Select Case** block to handle unforeseen _testexpression_ values. If no **Case**_expressionlist_ matches _testexpression_ and there is no **Case Else** statement, execution continues at the statement following **End Select**.
41
+
37
42
You can use multiple expressions or ranges in each **Case** clause. For example, the following line is valid:
38
43
39
44
@@ -72,7 +77,7 @@ Case 1 To 5 ' Number between 1 and 5, inclusive.
0 commit comments