+ Reply to Thread
Results 1 to 13 of 13

Adjusting the Array used with Scripting Dictionary?

  1. #1
    Forum Contributor
    Join Date
    12-29-2012
    Location
    usa
    MS-Off Ver
    Excel 2016
    Posts
    325

    Adjusting the Array used with Scripting Dictionary?

    Alright so I just started using arrays with scripting dictionary because I'm trying to do some Index Match formulas on workbooks that are over 300,000 rows.

    So I have the following code but I get an out of memory error sometimes when running it:

    Please Login or Register  to view this content.
    So pretty much what the above code is saying is that my unique identifier is in column 1 of both worksheets which is what the code is looking up. I want to return column 7 from worksheet 2, and put the result in column 16 of worksheet 1.

    The code works, but I get an out of memory error when running it on very large workbooks sometimes. I started using this code and my array was only the first 5 columns (x, 5), but it seems when I moved it to 7 columns (x, 7) that is when I'm getting the memory errors as each column has 300k+ rows. So I'm wondering if it's possible to adjust this array to only include my necessary columns (Columns 1 and Column 7) and leave out the other ones from the array?

    Thanks.

  2. #2
    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: Adjusting the Array used with Scripting Dictionary?

    A formula will be faster if the unique ID column is sorted and the last argument to MATCH is 1 or omitted.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Contributor
    Join Date
    12-29-2012
    Location
    usa
    MS-Off Ver
    Excel 2016
    Posts
    325
    Quote Originally Posted by shg View Post
    A formula will be faster if the unique ID column is sorted and the last argument to MATCH is 1 or omitted.
    I never used 1 in the index match. I need an exact match.

  4. #4
    Forum Contributor
    Join Date
    12-29-2012
    Location
    usa
    MS-Off Ver
    Excel 2016
    Posts
    325

    Re: Adjusting the Array used with Scripting Dictionary?

    I don't really understand the arrays within vba so is this code saying that the array is 7 columns wide:

    Please Login or Register  to view this content.
    Or is it saying its taking just columns 1 and 7? Because if it's possible to have the array just include 1 and 7 rather than the 5 additional columns, I think that will help with the memory issue.

  5. #5
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Adjusting the Array used with Scripting Dictionary?

    Quote Originally Posted by nobodyukno View Post
    I never used 1 in the index match. I need an exact match.
    If your data is sorted, as shg suggested, you can check for an exact match while still having the benefit of the speed of a binary search.

    If you wish to use your existing code I suggest you load two arrays- one for each column- and simply iterate those.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  6. #6
    Forum Contributor
    Join Date
    12-29-2012
    Location
    usa
    MS-Off Ver
    Excel 2016
    Posts
    325

    Re: Adjusting the Array used with Scripting Dictionary?

    Quote Originally Posted by xlnitwit View Post
    If your data is sorted, as shg suggested, you can check for an exact match while still having the benefit of the speed of a binary search.

    If you wish to use your existing code I suggest you load two arrays- one for each column- and simply iterate those.
    Does it matter if the data is sorted and not exactly the same length?

    For example, as this information is monthly, there could be new data added and old data removed. So the unique ID in A54 on the old month tab might not be the same as A54 on the new month tab, it might be A66 since new data was added.

  7. #7
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Adjusting the Array used with Scripting Dictionary?

    No- as long as it is sorted, you can use a binary search. If you are returning multiple columns of data for the same lookup value, you should put the MATCH formula into a separate column as well.

    The essence of the formula will be to use a binary VLOOKUP as well to ensure the matched value is the one you want
    =IF(VLOOKUP(A1,lookup_table,1)=A1,match(A1,lookup_table_column_1,1),"")

  8. #8
    Forum Contributor
    Join Date
    12-29-2012
    Location
    usa
    MS-Off Ver
    Excel 2016
    Posts
    325

    Re: Adjusting the Array used with Scripting Dictionary?

    Quote Originally Posted by xlnitwit View Post
    No- as long as it is sorted, you can use a binary search. If you are returning multiple columns of data for the same lookup value, you should put the MATCH formula into a separate column as well.

    The essence of the formula will be to use a binary VLOOKUP as well to ensure the matched value is the one you want
    =IF(VLOOKUP(A1,lookup_table,1)=A1,match(A1,lookup_table_column_1,1),"")
    Does the table and lookup arrays in the formula have to be actual tables? Or can I just reference columns? Because I tried the above formula as such:

    Please Login or Register  to view this content.
    and then did a regular index match:

    Please Login or Register  to view this content.
    The index match returned about 29k #N/A's and the binary formula returned about 15k blanks and 700 or so #N/A's.

  9. #9
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Adjusting the Array used with Scripting Dictionary?

    No, they do not have to be tables. You should only need to sort the Final sheet by column A.

  10. #10
    Forum Contributor
    Join Date
    12-29-2012
    Location
    usa
    MS-Off Ver
    Excel 2016
    Posts
    325

    Re: Adjusting the Array used with Scripting Dictionary?

    Quote Originally Posted by xlnitwit View Post
    No, they do not have to be tables. You should only need to sort the Final sheet by column A.
    And one more caveat is that column A are numbers stored as text so I guess I'm going to have to convert to numbers?

  11. #11
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Adjusting the Array used with Scripting Dictionary?

    You shouldn't have to. You just need to ensure that whatever you look up is the same data type as the lookup column.

  12. #12
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: Adjusting the Array used with Scripting Dictionary?

    Try change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    and see if you still have error or not.

  13. #13
    Forum Contributor
    Join Date
    12-29-2012
    Location
    usa
    MS-Off Ver
    Excel 2016
    Posts
    325

    Re: Adjusting the Array used with Scripting Dictionary?

    Quote Originally Posted by jindon View Post
    Try change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    and see if you still have error or not.
    Works perfectly.

    Thank you!

+ 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] Dictionary or Scripting.Dictionary. Binding Referencing Dim-ing. Sub routines and Function
    By Doc.AElstein in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 07-12-2016, 08:28 AM
  2. Scripting dictionary help
    By leanne2011 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-04-2016, 09:32 PM
  3. Cant get data to populate in VBA code from array & scripting dictionary
    By leanne2011 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-25-2015, 04:38 AM
  4. need help with scripting dictionary
    By leanne2011 in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 10-04-2014, 04:33 PM
  5. Create array with distinct items using scripting.dictionary
    By icyrius in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 09-06-2013, 04:36 PM
  6. [SOLVED] Scripting Dictionary
    By thisisgerald in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 12-18-2012, 01:30 PM
  7. [SOLVED] Scripting Dictionary help
    By williams485 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-13-2012, 08:22 AM

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