TYPENAME

TYPENAME(varname)

Returns the data type of the variable as a string (String).

varnameThe data type name, expression or variable (Object).

REMARKS
* The string returned by this function is the class name.
* It will return the same data type regardless of the case used for "varname". It is not case sensitive.
* For more information, refer to the TypeName Function page.
* You can use the VARTYPE function to return a number indicating the data type.
* The equivalent .NET function is [[Microsoft.VisualBasic.Information.TypeName]]
* For the Microsoft documentation refer to learn.microsoft.com

Debug.Print TypeName("String")                '= "String"  
Debug.Print TypeName("STRING") '= "String"
Debug.Print TypeName(1) '= "Integer"
Debug.Print TypeName(10.4) '= "Double"
Debug.Print TypeName(Null) '= ""

Dim vVariant As Variant
sVariant = CDec(10.5)
Debug.Print TypeName(vVariant) '= "Decimal"

Dim sTemp As String
Debug.Print TypeName(sTemp) '= "String"

Dim vArray() As Variant
vArray = Range("A1:A5")
Debug.Print TypeName(vArray) '= "Variant()"

Dim oRge As Range
Set oRge = Application.Selection
Debug.Print TypeName(oRge) '= "Range"

Dim oWsh As Worksheet
Set oWsh = ThisWorkbook.Worksheets("Sheet1")
Debug.Print TypeName(oWsh) '= "Worksheet"

Dim oWsh As Object
Set oWsh = ThisWorkbook.Worksheets("Sheet1")
Debug.Print TypeName(oWsh) '= "Worksheet"

© 2025 Better Solutions Limited. All Rights Reserved. © 2025 Better Solutions Limited Top