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?
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?
0
Saqib Husain, SyedEngineerAuthor Commented:
As a double
0
Saqib Husain, SyedEngineerAuthor Commented:
Actually I have this bad habit of not declaring variables. I often change types
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

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".
0
IrogSintaCommented:
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.

Ron
0

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
NorieVBA ExpertCommented:
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.
0
FarWestCommented:
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

0
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.
0
IrogSintaCommented:
Actually I showed you here that you can do that.  Look at the 5th post.

Ron
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.