Sunday, October 16, 2022

Data type - Currency

Data type Currency stored as 64-bit (8-byte) numbers in an integer format, maximum 15 digit number with 4 digit decimal point. Range between -922,337,203,685,477.5808 to 922,337,203,685,477.5807. The error code same as byte if we assigned out range "Run-time error '6' Overflow.

VBA Vode:

Option Explicit
Sub Examples_Currency()
    
    Dim DbNumA As Double, DbNumB As Double
    Dim CurNum As Currency
    
    DbNumA = 10.5678942563: DbNumB = 15.010234201356
    If Not Abs(DbNumA - DbNumB) > 999999999999999# Then
        CurNum = DbNumA - DbNumB
    Else
        MsgBox "Sorry! Data overflow.TQ"
    End If
    
    Debug.Print CurNum

End Sub

Note: 

The answer above example is -4.4423, only 4 decimal points is allow for data type currency even original data is more than that.

Microsoft Reference-Currency-data-type
Other Reference-Currency-data-type.htm

Practice makes perfect. Thank You.

macro enabled excel
excel macro
vba coding
vba code

No comments:

Post a Comment