+ Reply to Thread
Results 1 to 6 of 6

Clearing (not erasing or deleting) contents of Variant array

  1. #1
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Clearing (not erasing or deleting) contents of Variant array

    I have a variant array and i define it initially like the following:

    Please Login or Register  to view this content.
    I want to "clear" the contents of the array and start over populating it with other values. But i want the qty of entries in the array to stay the same.....and the data type as well.

    Please Login or Register  to view this content.


    i tried the following code but when it gets to the "2nd" For statement i get a run time error.




    I found this code to clear the array on line. The code used a slightly different array type but i thought i could still use this with my variant type array. Her eis the orringal code which does not crash.

    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Clearing (not erasing or deleting) contents of Variant array

    Hi,

    try changing this

    Please Login or Register  to view this content.
    To this

    Please Login or Register  to view this content.
    Steffen Thomsen

  3. #3
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Re: Clearing (not erasing or deleting) contents of Variant array

    nope.....that did not work either............i think it might have something to do with this array being defined as variant and the other one as an integer......not sure........

  4. #4
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Clearing (not erasing or deleting) contents of Variant array

    Hi,

    If you set the array later on with a range then try waiting to then with the redim

    Then use

    Please Login or Register  to view this content.
    This way you just overwrite the values in the array with the values of the new range

    Steffen Thomsen

  5. #5
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Re: Clearing (not erasing or deleting) contents of Variant array

    Steffen Thomsen good suggestion. However, i really wanted to just know how to "clear" the contents of the array........but i really like your suggestion.

    I figured out my problem...........my array is 2 dimensional so i had to do a redim in the following manner


    Please Login or Register  to view this content.
    if you do this the arrays contents get zeroed out.

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Clearing (not erasing or deleting) contents of Variant array

    1. Redim resets the elements of a Variant array to Empty, not 0.

    2. Unless you have set Option Base 1, your code redimensions the array to (0 to 26, 0 to 1)

    But I can't envision why this would be necessary.
    Entia non sunt multiplicanda sine necessitate

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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