VBA - Numerical Datatypes

There are range of different datatype for storing numbers. Each has their own application and know when and where to use them will help you write powerful code.

Note each of the datatypes have a range a variables that they can accept.

Here is short example showing how to create each data type.

Integer - Whole Numbers -  -2,147,483,648 to 2,147,483,647

Single - Decimal Numbers
            Negative Number Range -3.4028235E+38 through -1.401298E-45
            Positive Number Range 1.401298E-45 through 3.4028235E+38
Double - Decimal Numbers
            Negative Number Range -1.79769313486231570E+308 to -4.94065645841246544E-324
            Positive Number Range 4.94065645841246544E-324 to 1.79769313486231570E+308

Long - Whole Numbers - -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

Code Snippet:

Sub a4_2_Numbers()

Dim a As Integer

a = 1

Dim b As Single

b = 2.1

Dim c As Double

c = 2.1

Dim d As Long

d = 123432

End Sub

Related Sections

Python - Learn the python from the basics up. This fast track example code course will get you creating powerful python programs in no time.

Must Read Articles

VBA and Microsoft Excel - Getting the most out of excel with VBA programming
VBA and Microsoft Word - Getting the most out of word with VBA programming
Application Object - Using the applications features in your code.

Installing VBA and First Program - What do you need to start using visual basic application VBA.