Page 47 - Excel for Scientists and Engineers: Numerical Methods
P. 47
24 EXCEL: NUMERICAL METHODS
If reference.Rows.Count > 1 Then
R = equation.Row
Elself reference.Columns.Count > 1 Then
C = equation.Column
End If
Figure 2-2. Example of the VBA If ... Elself ... End If structure.
Logical Operators
The logical operators And, Or and Not can be used in LogicalExpression, as
in the following example.
If C >= 0 And C <= 9 Then
Select Case
VBA also provides the Select Case decision structure, similar to the ON
value GOT0 statement in BASIC. The Select Case statement provides an
efficient alternative to the series of Elself conditionN statements when conditionN
is a single expression that can take various values. The syntax of the Select
Case statement is illustrated in Figure 2-3.
Select Case TestExpression
Case ExpressionListl
statements
Case ExpressionList2
statements
Case ExpressionList3
statements
Case Else
statements
End Select
Figure 2-3. The VBA Select Case structure.
TestExpression is evaluated and used to direct program flow to the
appropriate Case. ExpressionListN can be a single value (e.g., Case 0), a list of
values separated by commas (e.g., Case 1, 3, 5), or a range of values using the
To keyword (e.g., Case 6 To 9). The optional Case Else statement is executed
if TestExpression doesn't match any of the values in any of ExpressionListN.
Looping
Loop structures in VBA are similar to those available in other programming
languages.