![](https://codky.com/wp-content/uploads/2023/12/How-to-use-Let-statement-in-VBA-1024x576.png)
Using Let for Assignment
VBA
Let variable = value
- variable: The name of the variable you’re assigning a value to.
- value: The value you’re assigning to the variable.
Example with Let
VBA
Sub ExampleWithLet()
Dim myVar As Integer
Let myVar = 10
MsgBox myVar
End Sub
Example without Let
VBA
Both of these examples do the same thing: they assign the value 10 to myVar and then display this value in a message box.
Sub ExampleWithoutLet()
Dim myVar As Integer
myVar = 10
MsgBox myVar
End Sub
Key Points
- The Let keyword is optional in VBA and is rarely used in modern code.
- Most VBA code simply assigns values to variables without using Let.
- Whether you use Let or not is mostly a matter of personal preference or coding style. However, omitting it is more common and aligns with contemporary practices.
- The Let keyword is more of a holdover from older versions of BASIC and is included in VBA for compatibility and historical reasons.