+ Reply to Thread
Results 1 to 10 of 10

Adding to a new variable array from an existing array

  1. #1
    Registered User
    Join Date
    09-23-2010
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    47

    Adding to a new variable array from an existing array

    Hi Folks,

    I'm having a bit of dilemma, I am trying to populate an array based on parts of a string.

    I have an array that contains data like this:

    Action1-Item1
    Action1-Item2
    Action1-Item3-ID
    Action1-Item4
    Action1-Item5
    Action2-Item1-ID
    Action2-Item-ID2

    What i am trying to do is loop through the original array, strip out the ID's and add them to a new array without adding duplicates.

    The kicker is the original array is subject to change and the amount with ID's is very likely to change so the second array needs to be variable. now what i have currently is:

    Please Login or Register  to view this content.
    ListArray is a global array

    Now my issue is that when i run the code i get an error that says:
    Compile Error
    Array already Dimensioned.

    Any help would be greatly appreciated.
    Last edited by Aussiexile; 11-17-2014 at 12:08 AM. Reason: Solved

  2. #2
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Adding to a new variable array from an existing array

    Hi..

    IDArray is a OneDimensional Array.

    You can only Redim Preserve the last Dimension in a Multidimensional Array.

  3. #3
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Adding to a new variable array from an existing array

    Try this.. if it is not exactly what you want.. hopefully you can adapt it..

    It will loop through your ListArray array.. splitting each element. if the Upper bound of the array = 2 it will then add that ID value into the Dictionary.

    Simple case of transposing the unique Keys of the Dictionary to the sheet at the end to get your new single dimension array (Z) shown.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by apo; 11-11-2014 at 02:36 AM.

  4. #4
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Adding to a new variable array from an existing array

    Quote Originally Posted by apo View Post
    Hi..

    IDArray is a OneDimensional Array.

    You can only Redim Preserve the last Dimension in a Multidimensional Array.
    Nope - you can do it with a 1D array but it must be declared as a dynamic array. Here it has been declared with fixed dimensions so it can't be resized at all, with or without preserve.
    Remember what the dormouse said
    Feed your head

  5. #5
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Adding to a new variable array from an existing array

    Hi Rory..

    Here it has been declared with fixed dimensions so it can't be resized at all, with or without preserve.
    I get that part now that you have pointed it out.. thanks

    But..

    you can do it with a 1D array but it must be declared as a dynamic array
    Can you elaborate on this part please.. I usually only 'play' with 2 dimensional arrays.. and was of the thinking that only the second dimension could be Preserved.. I am keen to learn how to do what you are saying..

  6. #6
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Adding to a new variable array from an existing array

    If you use Preserve you can only resize the last dimension. For a 1D array, the only dimension is also the last dimension, so:
    Please Login or Register  to view this content.
    for example.

  7. #7
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Adding to a new variable array from an existing array

    Got it .. thanks

  8. #8
    Registered User
    Join Date
    09-23-2010
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    47

    Re: Adding to a new variable array from an existing array

    Hi Folks,

    Thanks for all the replies, I did not know that about dimensioning of arrays!!

    Is there an easier way to to temporarily store data for comparison before writing to the worksheet?

    I have never used the Dictionary before. Can anyone direct me to a good eBook source for VBA coding with a slant towards excel?

    Thanks once again!!

  9. #9
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Adding to a new variable array from an existing array

    Did you try the attached Workbook i posted..? it should pretty much do what you asked for..

    Is there an easier way to to temporarily store data for comparison before writing to the worksheet?
    For what you want to do.. loop thru array.. strip out ID's and build a new array without dupes.. I can't think of anything that is direct as what i posted..

    Note: I only transposed the Z array to sheet to show the values.. you can whatever you want other than that with the resulting Z array..

    As for books.. not sure.. reading posts on Excel Help forums and googling is how i learned..

  10. #10
    Registered User
    Join Date
    09-23-2010
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    47

    Re: Adding to a new variable array from an existing array

    Thanks Apo,

    Worked a treat!!

+ 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. Can I make the row lookup array/range part in an array formula variable?
    By OLLY-7 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-18-2014, 09:06 AM
  2. [SOLVED] Summing Array Variable by Another Value in the Array (VBA Code)
    By lloydgodin in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 09-18-2013, 10:13 AM
  3. [SOLVED] Quick Array question - Copy array to another array then resize?
    By mc84excel in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-02-2013, 01:17 AM
  4. Adding an array of Dates to an Array of Times.
    By cummins in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-25-2011, 09:12 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