Working with strings

Like Excel, VBA can manipulate both numbers and text (strings). There are two types of strings in VBA: ■ Fixed-length strings are declared with a specified number of characters. The maximum length is

65,535 characters.

■ Variable-length strings theoretically can hold up to 2 billion characters.

Each character in a string requires 1 byte of storage, plus a small amount of storage for the header of each string. When you declare a variable with a Dim statement as data type String, you can specify the length if you know it (that is, a fixed-length string), or you can let VBA handle it dynamically (a variable-length string).

In the following example, the MyString variable is declared to be a string with a maximum length of 50 characters. YourString is also declared as a string; but it's a variable-length string, so its length is unfixed.

Dim MyString As String * 50 Dim YourString As String

0 0

Post a comment