ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA code to "reset" application run and empty preserved arrays (https://www.excelbanter.com/excel-programming/389001-vba-code-reset-application-run-empty-preserved-arrays.html)

[email protected]

VBA code to "reset" application run and empty preserved arrays
 
Hi,

I've been helping write some VBA code which is executed from a button
on an excel worksheet. Data is read in from the sheet, calculations
are performed in multiple modules (public variables). The problem is
that as some of the arrays which hold the data are dimensioned using
Redim Preserve, which means that when the program ends, the data is
still in the arrays.

If the program is run a 2nd time from the button on the worksheet,
lots of errors are generated in the program, as the arrays are full of
data from the first run. If "reset" is clicked in the VB editor, the
arrays empty & the code runs fine. Is there a way to code this
'reset' button & empty the arrays?

Cheers,
Kate


John.Greenan

VBA code to "reset" application run and empty preserved arrays
 
Look in the Excel online help for the keyword "erase" - gets rid of arrays....

--
www.alignment-systems.com


" wrote:

Hi,

I've been helping write some VBA code which is executed from a button
on an excel worksheet. Data is read in from the sheet, calculations
are performed in multiple modules (public variables). The problem is
that as some of the arrays which hold the data are dimensioned using
Redim Preserve, which means that when the program ends, the data is
still in the arrays.

If the program is run a 2nd time from the button on the worksheet,
lots of errors are generated in the program, as the arrays are full of
data from the first run. If "reset" is clicked in the VB editor, the
arrays empty & the code runs fine. Is there a way to code this
'reset' button & empty the arrays?

Cheers,
Kate



NickHK

VBA code to "reset" application run and empty preserved arrays
 
Kate,
Whilst I would not recommend it, there is End. However, this is rather
abrupt termination of code and clearing of variable.
Go John's way of explicitly Erasing each array, unless you want to
<probably cause more problems than it solves with End, which is the code
equivalent of the Reset button.

NickHK

wrote in message
oups.com...
Hi,

I've been helping write some VBA code which is executed from a button
on an excel worksheet. Data is read in from the sheet, calculations
are performed in multiple modules (public variables). The problem is
that as some of the arrays which hold the data are dimensioned using
Redim Preserve, which means that when the program ends, the data is
still in the arrays.

If the program is run a 2nd time from the button on the worksheet,
lots of errors are generated in the program, as the arrays are full of
data from the first run. If "reset" is clicked in the VB editor, the
arrays empty & the code runs fine. Is there a way to code this
'reset' button & empty the arrays?

Cheers,
Kate





All times are GMT +1. The time now is 04:38 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com