Saqib Husain
asked on
VBA Uninitializing a variable
How do I uninitialize a variable so that the isempty() function returns a true? The variable is a variant.
I think the best approach would not to use a Variant. How is your variable being used?
ASKER
As a double
ASKER
Actually I have this bad habit of not declaring variables. I often change types
You can still change types if you explicitly type a variable, and Variants are the least efficient and largest variable type so you might want to change your "bad habit".
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You really should declare all variables, not doing so can lead to problems, eg unexpected results, hard to debug code etc
If you add Option Explicit at the top of each module you'll be forced to declare all variables.
PS You can use Tools>Options... Require Variable Declaration in the VBE to automatically add Option Explicit to every module.
If you add Option Explicit at the top of each module you'll be forced to declare all variables.
PS You can use Tools>Options... Require Variable Declaration in the VBE to automatically add Option Explicit to every module.
you can have a variable that you keep without assigning values to it, and when you want to uninitialized any other variables just assign that variable to it
like this
like this
Dim Vartest As Variant
Dim xEmptyVar As Variant
Vartest = "SomeData"
Vartest = xEmptyVar
Debug.Print IsEmpty(Vartest)
ASKER
Martin, you showed me how to uninitialize it using = Empty
I used it and it works just fine. But your comment is now gone.
I used it and it works just fine. But your comment is now gone.