Page 50 - Excel for Scientists and Engineers: Numerical Methods
P. 50
CHAPTER 2 FUNDAMENTALS OF PROGRAMMING WITH VBA 27
using the Exit For (from a For ... Next loop or For Each ... Next loop) or Exit Do
(from a Do While ... loop). The Exit statement will normally be located within an
If statement. For example,
If CellContenkValue c= 0 Then Exit For
Use the Exit Sub or Exit Function to exit from a procedure. Again, the Exit
statement will normally be located within an If statement.
Exit statements can appear as many times as needed within a procedure.
VBA Data Types
VBA uses a range of different data types. Table 2-6 lists the built-in data
types. Unless you declare a variable's type, VBA will use the Variant type. You
can save memory space if your procedure deals only with integers, for example,
by declaring the variable as Integer. The keyword Dim is used to declare a
variable's data type, as will be described in a following section.
Table 2-6. VBA's Built-in Data Types
Data Type Storage Required Range of Values
Boolean (Logical) 2 bytes True or False
Integer 2 bytes -32,768 to 32,767
Long integer 4 bytes -2,147,483,648 to 2,147,483,647
Single precision 4 bytes -3.402823E+38 to -1.401298E-45
for negative values; 1.401298E-45
to 3.402823E+38 for positive
values
Double precision 8 bytes -1.797693 13486232E+308 to
-4.9406564584 1247E-324 for
negative values;
4.94065645841247E-324 to
1.797693 13486232E+308 for
positive values
Currency 8 bytes -922,337,203,685,477.5808 to
922,337,203,685,477.5807
Date 8 bytes
Object 4 bytes Any Object reference
String 1 bytekharacter
Variant 16 bytes Any numeric value up to the
+ 1 bvte/character range of a Double or anv text