How do you destroy a variable?

phantom1975

MrExcel MVP
Joined
Jun 3, 2002
Messages
3,962
Once I have a variable set within a procedure, how can I destroy the value of the variable within the procedure? I'm not sure, but I thought it was something like:

MyVar = Nothing

_________________
Pass on what you have learned. Support this great website by clicking on the sponsor's ads!.
This message was edited by phantom1975 on 2002-09-17 20:08
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

white6174

Board Regular
Joined
May 6, 2002
Messages
137
THAT SHOULD WORK


OR
MyVar =0


OR
MyVar ="" (NOT SURE)

STEVE W
This message was edited by white6174 on 2002-09-17 20:17
 

phantom1975

MrExcel MVP
Joined
Jun 3, 2002
Messages
3,962
I'm afraid that 0 and "" still are values. Zero is an integer and "" is a string.
 

white6174

Board Regular
Joined
May 6, 2002
Messages
137
I believe that when a variable is nothing it is seen as zero in a calculation.

steve w
 

Hero-0952

Wizard Deluxe
Joined
Jun 11, 2002
Messages
348

ADVERTISEMENT

Hey Phantom,

I pasted the wrong link...BRB.

Ok, I found the link. There are several references here to the MyVar= :
http://www.provider.com.br/infobahia/101tips_7.htm

I was also looking at another thread on another board that seems to agree with what you said Phantom; that even a 0 is a value:

http://www.experts-exchange.com/Applications/MS_Office/Q_11706499.html

Regards,

ViperGTS

________________
This message was edited by ViperGTS on 2002-09-17 21:05
 

Jay Petrulis

MrExcel MVP
Joined
Mar 17, 2002
Messages
2,040
Hi,

I believe that white6174 is correct. It depends on the declaration of your variable.

Set objects to nothing (possibly .Delete may work, too).
For numerics, you can set them to zero.
For strings, you can set them to "".

For the non-objects, you can also set them to Empty to give them their default variables

x = Empty

will set x back to its default.

I don't believe that you can actually destroy variables unless you use the following statement in your code

End

although that deletes a whole bunch and ends your routine.

In general, once initialized the variable is created and stays that way until the procedure is out of scope. Possibly others know a way to explicitly destroy a variable, but I do not.
 

phantom1975

MrExcel MVP
Joined
Jun 3, 2002
Messages
3,962
AWESOME link Viper! I copied it to a Word document and it's 82 pages long. Looks like I have some bathroom reading for a few weeks.
 

Forum statistics

Threads
1,144,273
Messages
5,723,436
Members
422,497
Latest member
dougy99

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top