+ Reply to Thread
Results 1 to 7 of 7

jagged arrays

  1. #1
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    jagged arrays

    Hi all,

    I need to merge three 2D arrays into one. I have arry1, 2 and 3 which come from three different sheets, they are all of the same size. Now I want to create a consolidated array with all unique Materials of the three arrays and if the Material is not unique I want to replace all data points that contain " - " with whatever the matched array contains (either " x " or " - " as well).

    I created a simplified sample workbook to illustrate things further with a "desired output" sheet to show how the end result should look like. Below is the code I have so far to combine at least 2 of these arrays, however, that also doesn't seem quite right yet as some Materials are overwritten or neglected.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: jagged arrays

    Hello esbencito,

    This macro works with the data layout that appears in your posted workbook. If the original workbook layout is different then the macro will need to be updated. There is a button on the worksheet "Desired Result" to run the macro.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Re: jagged arrays

    Hi Leith,

    Thanks so much for taking the time and effort to help me out on this!

    Your code works really well in the sample data. The only call-out I would have is that it doesn't ignore Materials with 0 door count (211580009095) which it should. Also, my actual data layout is a little more complex as you had already guessed and I am not sure how to adjust the code to make it work as I'm very unfamiliar with scripting dictionaries .

    The data in my actual workbook is coming from three other external workbooks and the data needs to be pasted back only to certain sections of the summary sheet. You can see what I mean and how the layout looks like by checking my previous thread. Would really appreciate if you have the time to look into this further.

    https://www.excelforum.com/excel-pro...nto-sheet.html

    Generally speaking, do you think the scripting dictionary method is superior to jagged arrays, especially with large data sets? Would this also be technically solvable with jagged arrays?

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: jagged arrays

    Hello Hello esbencito,

    After downloading the workbook from your previous post and reviewing it, the macro I posted will not work and is inadequate for the task. I do have a couple of questions.
    1. Which sections besides the "Clusters" will be updated ?
    2. Will the output be going to the sheet named "Desired Result" ?

    VBA does support jagged arrays. When checking for duplicates it is better to use either a Collection object or Dictionary object. My preference is to use a Dictionary since no additional coding is needed to check if a key already exists or returning a list of all keys or all items. In VBA a jagged array is simply a 1-D array that holds an array in each element. An array can be resized dynamically in VBA but only the last dimension of the array can be changed. Using a Dictionary with large amounts of data allows a quick check for duplicates in a jagged arrays. Using big O notation to compare lookup times, the dictionary is O(1) constant time complexity while just iterating through the primary array to check for duplicates results in O(n) linear time complexity,

    Example of Jagged Array
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Re: jagged arrays

    Hi Leith,

    Thanks for reviewing my previous post!

    1. All sections of the Range("PasteArea") will need to be updated!
    2. The output should be pasted into the Sheet("TOTAL"). The "Desired Result" sheet is just to double check if the output is correct.

    Do you have an idea how such a dictionary solution could look like to get the required results?

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: jagged arrays

    Hello esbencito,

    I have a few ideas how to approach this problem. It is a bit complex due to it's size and amount of data to process. Execution speed will be a big part of the decision making process along with flexible coding.

    Since VBA Variants can be used as arrays, it makes the coding more flexible since an object reference can saved in the array and not just strings and numbers. Using an Object reference saves time, memory, and provides direct access to the object itself. This can preclude the need to save an array of the object's values along with a reference to the object. This is the elegance of object oriented programming.

    I might use the Dictionary to store and access the jagged arrays on the worksheets in a recursive fashion. There may be a better approach to updating the sections. But, I need to review the data layout more closely. I'll keep you posted.

  7. #7
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Re: jagged arrays

    Thanks Leith, this sounds promising!

+ 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. Using jagged array to associate one to many
    By tobias1010 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-14-2018, 11:01 PM
  2. Jagged Array vba
    By tobias1010 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-12-2018, 01:37 PM
  3. [SOLVED] Jagged Arrays: Syntax Clarificatiuon
    By cmore in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-26-2016, 05:46 PM
  4. Declaring multiple multi-dimensional arrays (jagged arrays) - compile error?
    By dfribush in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-20-2013, 05:06 PM
  5. [SOLVED] Print to worksheet and Jagged Array
    By abousetta in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-07-2012, 07:50 PM
  6. Jagged Pie Charts
    By Sionos in forum Excel General
    Replies: 0
    Last Post: 09-25-2007, 05:54 AM
  7. [SOLVED] soften jagged edges of pie charts
    By zen in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 06-17-2005, 02:05 PM

Tags for this Thread

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