Christiaan
Board Regular
- Joined
- Nov 5, 2012
- Messages
- 81
Hello everyone.
I am having trouble finding the datatype in a cell, using a function.
I have the sub to pass the argument into the function, the function itself is detecting the datatype (somehow it shows 0 as double, no decimals specified in the cell).
But in the subroutine the myCheck value remains empty.
What am I missing here? Please see the code below...
I am having trouble finding the datatype in a cell, using a function.
I have the sub to pass the argument into the function, the function itself is detecting the datatype (somehow it shows 0 as double, no decimals specified in the cell).
But in the subroutine the myCheck value remains empty.
What am I missing here? Please see the code below...
Code:
Sub FindTypeName()
Dim rng As Range
Dim myCheck As String
Set rng = Range("BG2:BG10")
For Each cell In rng
myVar = cell.Value
If myVar = "" Then
'Do nothing
Else
myCheck = Get_Var_Type(myVar)
If myCheck = "String" Then cell.Value = ""
End If
Next
End Sub
Function Get_Var_Type(myVar) As String
If VarType(myVar) = vbNull Then
myCheck = ""
ElseIf VarType(myVar) = vbInteger Then
myCheck = "Integer"
ElseIf VarType(myVar) = vbLong Then
myCheck = "Long integer"
ElseIf VarType(myVar) = vbSingle Then
myCheck = "Single"
ElseIf VarType(myVar) = vbDouble Then
myCheck = "Double"
ElseIf VarType(myVar) = vbCurrency Then
myCheck = "Currency"
ElseIf VarType(myVar) = vbDate Then
myCheck = "Date"
ElseIf VarType(myVar) = vbString Then
myCheck = "String"
ElseIf VarType(myVar) = vbObject Then
myCheck = "Object"
ElseIf VarType(myVar) = vbError Then
myCheck = "Error"
ElseIf VarType(myVar) = vbBoolean Then
myCheck = "Boolean"
ElseIf VarType(myVar) = vbVariant Then
myCheck = "Variant"
ElseIf VarType(myVar) = vbDataObject Then
myCheck = "Data object"
ElseIf VarType(myVar) = vbDecimal Then myCheck = "Decimal"
ElseIf VarType(myVar) = vbByte Then
myCheck = "Byte"
ElseIf VarType(myVar) = vbUserDefinedType Then
myCheck = "Other"
ElseIf VarType(myVar) = vbArray Then
myCheck = "Array"
Else
myCheck = ""
End If
End Function