VBA variable name naming rules: 1. The first character must be a letter; 2. The name can contain letters, numbers, and underscores; 3. The name cannot contain spaces, periods, exclamation points, or characters. [@, &, $ and #]; 4. The name can contain up to 255 characters.
VBA variable name naming rules:
1. VBA has the following naming rules for subroutines and functions:
1) The first character must be a letter.
2) The name can contain letters, numbers and underscores.
3) The name cannot contain spaces, periods, exclamation points, or the characters @, &, $, and #.
4) The name can contain up to 255 characters.
2. Variable type
Variables are used to save process data. Below are the variable types used in VBA. The naming rules for variable names are the same as for procedure names. The definition of variables uses Dim variable name as data type
3. Variable declaration
The following will create a process whose function is to prompt the user to enter a name and then display it in the message box.
Public Sub KnowYourName() Dims Name As String sName = InputBox("Enteryourname:") MsgBox "Hi"&sName End Sub
Where Name is a string variable, there is no need to provide a data type in the Dim statement. If no data type is provided, the variable will be assigned the default data type in VBA, Variant. If the data type is not defined, it will take up space and increase the running time.
Dim iNumberOfStudents as Integer Dim dTestDate as Date 'The following line creates a variable length string Dim sLastName as String 'The next line creates a 2char. Fixed length string Dim sState as String*2
You can add comments by starting with a single quote
The above is the detailed content of What are the naming rules for vba variable names?. For more information, please follow other related articles on the PHP Chinese website!