VBA is what? VBA is one of the Microsoft, in VB (Visual basic, a Visual development environment) in the language, for the development of automation application in Excel, you can use VBA to realize the automation, can greatly improve the efficiency of the user's work, today, we have to learn this language,
About how to open in Excel VBA programming window, there is not in detail, we can have a look at the baidu,
For a computer language, it is the most basic grammar, first to get to know the types of data in VBA,
1, VBA is commonly used in numeric types are:
Byte (Byte) without type declaration character;
Integer (int) statement character is: the %;
Characters Long (Long integer) statement is: & amp;;
A Decimal (Decimal) without type declaration character;
Singles (single precision floating point) statement character is: the! ;
Double character (double-precision floating-point type) statement is: #,
Often don't clearly before single-precision floating-point type and double-precision floating-point type, the difference between a single precision floating point with 4 bytes to represent a decimal, double-precision floating-point type with 8 bytes decimal representation, so double than single precision said scope is big,
There are two commonly used string data type: the type declaration characters are $
String * Length (f) the format of the statement is: String *] [specify Length, the Length can be stored for 1-65400 characters, in this state, for not meet the characters of fixed Length setting, VBA will adopt the method of long truncated fill resolved,
Variable-length string can store the length of the string variable, can store up to a maximum of 2 billion characters,
2, VBA commonly used other data types,
Boolean (Boolean) no type declarations characters,
Currency (currencies) statement character is: the @, it is mainly used for monetary or fixed small digital computing,
No type declarations character Data type (date),
Object (objects) no type declarations characters,
The Variant (body) no type declarations characters,
3, the array type
Fixed size array using Dim to statements, such as declaring a 10 the fixed length of the string array:
Dim Department (1 To 10) As String '
Dynamic array
Statement: Dim Department () As String
Declare variables in the VBA's solution: Dim variable name As data type
In addition to the Dim statement, you can also use Public statements, Private statements, Static statement declaring variables, their difference is their scope is different, among them, the Public scope biggest, followed by Private, Static is the smallest, the scope of the Dim is related to its position statement, the scope of the
Said part of the data type can be used to replace the identifier, such as Integer (Integer) can be used: Dim variable name %
To the variable assignment expressed as: [Let] variable name=data, including the Let can omit
For example:
Sub BLFZ ()
Dim STR As String
Str="VBA and pivot table"
Range (" A1 "). value=https://bbs.csdn.net/topics/str
End Sub
Be evaluated if the variable is the date that you need to write the date between two # symbols, such as: the Let d=# 2015-3-14 #,
Be evaluated if the variable is an object, use the following statement:
Sub FZDX ()
Dim RNG As Range
The Set RNG=Worksheets (" sheet1 "). The Range (" A1 ")
Rng. Value="https://bbs.csdn.net/topics/VBA and pivot table"
End Sub
This function is used in the sheet1 form A1 cell write "VBA and pivot table" this string of characters,
VBA constants in the declaration and assignment
Declare constants: Const=numerical constants As data type
For example: Const pai As Single=3.14159, according to declare a decimal constants, value of 3.14159