how to define and initialize variable in vba code example

Example 1: vba declare variable with value

Dim myString As String:  myString = "aaa bbb"
Dim myStringCaps As String:  myStringCaps = UCase("aaa bbb")
Dim myPart As Variant: myPart = Split(myString)
Dim ws As Worksheet: Set ws = ThisWorkbook.Worksheets(1)
Const MY_CONST As String = "Value"

Example 2: vba dim and set value

' More visual (':' is just a line separator)
Dim sTest As String:  sTest = clientsToTest(i)
Dim sVariant As Variant: sVariant = Split(sTest)
' Objects
Dim ws as New Workbook

Tags:

Html Example