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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
THAT SHOULD WORK


OR
MyVar =0


OR
MyVar ="" (NOT SURE)

STEVE W
This message was edited by white6174 on 2002-09-17 20:17
 
Upvote 0
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,575
Messages
6,120,344
Members
448,956
Latest member
Adamsxl

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
Back
Top