VBA Uninitializing a variable

How do I uninitialize a variable so that the isempty() function returns a true? The variable is a variant.
LVL 43
Saqib Husain, SyedEngineerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
I think the best approach would not to use a Variant. How is your variable being used?
Saqib Husain, SyedEngineerAuthor Commented:
As a double
Saqib Husain, SyedEngineerAuthor Commented:
Actually I have this bad habit of not declaring variables. I often change types
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

Martin LissOlder than dirtCommented:
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".
You can do this:
NameOfVariable = Empty

The above only works for variants.  If possible though, you should declare your variables and only declare them as variants when truly necessary.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NorieAnalyst Assistant Commented:
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.
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
Dim Vartest As Variant
Dim xEmptyVar As Variant
Vartest = "SomeData"
Vartest = xEmptyVar
Debug.Print IsEmpty(Vartest)

Open in new window

Saqib Husain, SyedEngineerAuthor Commented:
Martin, you showed me how to uninitialize it using     = Empty

I used it and it works just fine. But your comment is now gone.
Actually I showed you here that you can do that.  Look at the 5th post.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.