VBA Variable Declarations
'Display the value of the variable in a dialog box
Sub variables()
'Declaring the variable
Dim my_variable As Integer
'Assigning a value to the variable
my_variable = 12
'Displaying the value of my_variable in a MsgBox
MsgBox my_variable
'Example : whole number
Dim nbInteger As Integer
nbInteger = 12345
'Example : decimal number
Dim nbComma As Single
nbComma = 123.45
'Example : text
Dim varText As String
varText = "Excel-Pratique.com"
'Example : date
Dim varDate As Date
varDate = "06.04.2012"
'Example : True/False
Dim varBoolean As Boolean
varBoolean = True
'Example : object (Worksheet object for this example)
Dim varSheet As Worksheet
Set varSheet = Sheets("Sheet2") 'Set => assigning a value to an object variable
'Example of how to use object variables : activating the sheet
varSheet.Activate
Dim last_name As String, first_name As String, age As Integer
End Sub
Sub variables()
'Declaring the variable
Dim my_variable As Integer
'Assigning a value to the variable
my_variable = 12
'Displaying the value of my_variable in a MsgBox
MsgBox my_variable
'Example : whole number
Dim nbInteger As Integer
nbInteger = 12345
'Example : decimal number
Dim nbComma As Single
nbComma = 123.45
'Example : text
Dim varText As String
varText = "Excel-Pratique.com"
'Example : date
Dim varDate As Date
varDate = "06.04.2012"
'Example : True/False
Dim varBoolean As Boolean
varBoolean = True
'Example : object (Worksheet object for this example)
Dim varSheet As Worksheet
Set varSheet = Sheets("Sheet2") 'Set => assigning a value to an object variable
'Example of how to use object variables : activating the sheet
varSheet.Activate
Dim last_name As String, first_name As String, age As Integer
End Sub
Comments
Post a Comment