+ Reply to Thread
Results 1 to 4 of 4

erase an array resulting in array not populated when the macro runs again

  1. #1
    Forum Contributor aprildu's Avatar
    Join Date
    04-13-2014
    Location
    Barrie,On, Canada
    MS-Off Ver
    Excel 2016
    Posts
    175

    erase an array resulting in array not populated when the macro runs again

    I have a two dimentional array that's redim preserved:

    Please Login or Register  to view this content.
    If I don't have "erase ar()" line then if I run a few times (consecutively) then I get the same array stacked multiple times. If I have that line then I don't get any results (if I run multiple times - the first time is OK)

    If I don't run it consecutively then there's no issue. Just wondering why and if it's OK to run multiple times(in case client does it even there's no reason to run multiple times). Any insight is appreciated!
    Last edited by aprildu; 06-14-2019 at 03:00 PM.

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: erase an array resulting in array not populated when the macro runs again

    For a static array, the erase function will empty the data elements but leave the elements with empty values.
    For a dynamic array, the erase function destroys the array and the empties the memory, requiring a complete rebuild of the array to restore the elements. Since your erase statement is outside the Do loop that builds the array and after the statement that applies the array value, I don't see how it would affect what the array produces. But if it the code posted is actually inside another loop and not shown for this post, then the the behavior could be the result of how the erase function is treating your array.

    Perhaps if you explained what you are trying to do, we could offer an alternative solution without using the erase fuction.
    Last edited by JLGWhiz; 06-14-2019 at 11:12 PM.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  3. #3
    Forum Contributor aprildu's Avatar
    Join Date
    04-13-2014
    Location
    Barrie,On, Canada
    MS-Off Ver
    Excel 2016
    Posts
    175

    Re: erase an array resulting in array not populated when the macro runs again

    I found the issue. I didn't set the x=0 before the loop ( I thought I did in the real code) and that's why it kept adding up. It was driving me bunkers! Thank you for replying!
    Last edited by aprildu; 06-15-2019 at 06:04 PM.

  4. #4
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: erase an array resulting in array not populated when the macro runs again

    Thanks for the feedback,
    regards, JLG

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Counting Unique values with date criteria as an array formula resulting in #N/A
    By Clooney003 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-22-2019, 12:51 PM
  2. Looking up the lowest populated value in an array
    By jamot in forum Excel General
    Replies: 3
    Last Post: 07-29-2016, 08:37 AM
  3. Comparing a string to values in an array resulting in a Run time Error 1004
    By sgreni in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-15-2009, 04:21 PM
  4. Array Value populated from cell A2:A38
    By Chris Baluyot in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-22-2008, 02:04 AM
  5. [SOLVED] Positioning Numeric Values Resulting from 6 Column Array Formula
    By Sam via OfficeKB.com in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-05-2006, 12:25 PM
  6. [SOLVED] Positioning Numeric Values Resulting from 6 Column Array Formula
    By Sam via OfficeKB.com in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-04-2006, 10:10 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1