Working with data types in variables and constants
In this recipe, we will be investigating the different data types you can assign to variables and constants.
Getting ready
Open Excel and make sure that Book1 is active, and save the file as DatTypes.xlsm
. Open the VBA Editor by pressing Alt + F11. In the VBA editor, click Insert | Module to create a new module in Book1. On the menu bar, click View | Locals Window, if the Locals window is not already active.
How to do it…
- In the code window for
Module1
, create a new Sub procedure calledData_Types
:Sub Data_Types() End Sub
- Once done, declare the following variables. Ensure that the data types are added exactly as per the example:
Sub Data_Types() Dim Small As Byte Small = 75 Dim Big As Integer Big = 3333 Dim Large As Long Large = 800011100 Dim Yes As Boolean Yes = True Dim Dec As Double Dec = 3.14159 Dim Text As String Text = "MyName" Dim DOB As Date DOB = #12/25/1990# Dim Price As Currency Price...