+ Reply to Thread
Results 1 to 38 of 38

VBA - How to Ignore array dimension mismatches? - move to next

  1. #1
    Registered User
    Join Date
    11-07-2018
    Location
    Sydney Australia
    MS-Off Ver
    2016 Pro
    Posts
    74

    VBA - How to Ignore array dimension mismatches? - move to next

    I have 2 arrays, my VBA macro uses these arrays to match one against the other, but there can be a different amount of entries in 1 array than the other.

    When there is a different amount of entries, the macro stops on Err.Raise -1001, , "Array dimensions do not match", but I want it to skip and continue matching the available entries.

    How do I skip the blanks and match entries that are available?


    Please Login or Register  to view this content.

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

    Re: VBA - How to Ignore array dimension mismatches? - move to next

    Quote Originally Posted by Lee_of_Excel View Post
    I have 2 arrays, my VBA macro uses these arrays to match one against the other, but there can be a different amount of entries in 1 array than the other.
    What do you want when you find match?

    You can loop through all the dimensions or use Match function to find, if needed, so why do you need to ignore the dimension?

  3. #3
    Registered User
    Join Date
    11-07-2018
    Location
    Sydney Australia
    MS-Off Ver
    2016 Pro
    Posts
    74

    Re: VBA - How to Ignore array dimension mismatches? - move to next

    Hi Jindon,

    Thanks for your reply.

    I am using it in a gale shapley (stable marriage) matching algorithm and in summary I am matching A Man and preferences of Women to A Woman and preferences of Men , my current macro works well, but only when there are equal numbers in my 2 arrays.

    The full problem that I am trying to solve is to be able to enter:
    a list of men with their preferences on sheet 1,
    a list of Women with their preferences on sheet 2
    and then results populate on sheet 3.

    It is ok if some don't have a match, but I need my code to be able to keep moving even if there are e.g 15 men all with different numbers of preferences to 80 women with different numbers of preferences.

    my complete code is:
    Please Login or Register  to view this content.
    I have attached my spreadsheet with the macro - Matching1.xlsm and the spreadsheet of how I want it to work - MatchingGoal.xlsm

    And I have another thread about the full problem at:
    HTML Code: 
    Attached Files Attached Files
    Last edited by Lee_of_Excel; 04-24-2019 at 12:52 AM. Reason: grammar mistakes

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

    Re: VBA - How to Ignore array dimension mismatches? - move to next

    I don't fully understand the logic to "match".
    This outputs if 1st preference in both men/women matches, also no preference.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    11-07-2018
    Location
    Sydney Australia
    MS-Off Ver
    2016 Pro
    Posts
    74

    Re: VBA - How to Ignore array dimension mismatches? - move to next

    Thanks Jindon, your code works well for the first match.

    I don't have a great understanding of how the match works either, unfortunately I inherited the matching code and am stuck with trying to modify it.

    I have another style of the same code which also works but it places the results in a msgbox.

    This also has the same issue though, I need to be able to enter different amounts of entries and also want to use the Sheet1, Sheet2, Sheet3 style like you have created.

    Thanks again for your help

    Cheers

    Please Login or Register  to view this content.

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

    Re: VBA - How to Ignore array dimension mismatches? - move to next

    Sorry, but if you don't understand the logic to match, I can not modify my codes.

    If you want to output to the sheet instead of msgbox
    replace
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    11-07-2018
    Location
    Sydney Australia
    MS-Off Ver
    2016 Pro
    Posts
    74

    Re: VBA - How to Ignore array dimension mismatches? - move to next

    Thanks very much for your help Jindon, yes unfortunately my VBA skills are only basic so I am having trouble understanding some of the elements.

    Cheers
    Lee
    Last edited by jeffreybrown; 04-25-2019 at 08:01 PM. Reason: Removed full quote!

  8. #8
    Registered User
    Join Date
    11-07-2018
    Location
    Sydney Australia
    MS-Off Ver
    2016 Pro
    Posts
    74

    Re: VBA - How to Ignore array dimension mismatches? - move to next

    Quote Originally Posted by jindon View Post
    Sorry, but if you don't understand the logic to match, I can not modify my codes.

    If you want to output to the sheet instead of msgbox
    replace
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    Hi Jindon, do you happen to understand Python?

    I have the python algorithm below, but cannot translate it in to Excel VBA.

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    11-07-2018
    Location
    Sydney Australia
    MS-Off Ver
    2016 Pro
    Posts
    74

    Re: VBA - How to Ignore array dimension mismatches? - move to next

    Hi Jindon and All,

    It has been a while, but can I please ask one more favour.

    With your code, how can I use the split function to pull data from 2 tables, which may be different in size?

    Currently I have Trainee names in Column B, from B4:B7, followed by their preferences of sites in row (C4:H7),

    Then I have Sites from B12:B22, followed by their preference of trainees in row (C12:H22)

    The amount of trainees and amount of sites may vary and the number of their preferences may vary.

    I want to try and use your VBA code to recognise data entered in the 2 tables.

    I have enclosed the spreadsheet and screenshot as an example.

    Thanks again

    Lee

    The 'Non Working' code is:

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

  10. #10
    Registered User
    Join Date
    11-07-2018
    Location
    Sydney Australia
    MS-Off Ver
    2016 Pro
    Posts
    74

    Re: VBA - How to Ignore array dimension mismatches? - move to next

    Quote Originally Posted by jindon View Post
    This outputs if 1st preference in both men/women matches, also no preference.
    Also even if I could run the same module multiple times that would be fine for example. If I run the module the first time, it matches 1st preference in both Trainee/site matches, then I could run a second module which is the same, but looks at second preference for rows that weren't able to match using the 1st preference.

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

    Re: VBA - How to Ignore array dimension mismatches? - move to next

    Sorry, but I don't even read the code built by someone else and touch it.
    If you upload a workbook with the data and the EXACT results that you want clearly showing what you are trying to achieve, it may help.

  12. #12
    Registered User
    Join Date
    11-07-2018
    Location
    Sydney Australia
    MS-Off Ver
    2016 Pro
    Posts
    74

    Re: VBA - How to Ignore array dimension mismatches? - move to next

    Quote Originally Posted by jindon View Post
    Sorry, but I don't even read the code built by someone else and touch it.
    If you upload a workbook with the data and the EXACT results that you want clearly showing what you are trying to achieve, it may help.
    Thanks again for your help Jindon, I have now removed the code and provided a description for the results that I am trying to get in the Workbook.

    Goal:

    1. To compare Table1 (Blue) and Table2 (Orange) - both may change in the amount of entries. e.g 70 trainees vs 140 sites etc

    2. Match the preferences between Table1 and Table2 (even if it can only match the first preference of each) e.g Trainee 01 first preference is site 04 and Site 04 first preference is trainee 01 - so they have a match

    3. Fill the match results in Table3 (green)

    4. If the results have any with no match, I would like to run a copy of the code a second time, which will compare second preference and fill in the data in Table3 and so on until the most possible have a match from their preference list
    Attached Files Attached Files

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

    Re: VBA - How to Ignore array dimension mismatches? - move to next

    This is how I understand...
    Please Login or Register  to view this content.
    Note:
    I need to go out shortly, so if any further adjustment or something else, my response will be late.

  14. #14
    Registered User
    Join Date
    11-07-2018
    Location
    Sydney Australia
    MS-Off Ver
    2016 Pro
    Posts
    74

    Re: VBA - How to Ignore array dimension mismatches? - move to next

    Quote Originally Posted by jindon View Post
    This is how I understand...
    Please Login or Register  to view this content.
    Note:
    I need to go out shortly, so if any further adjustment or something else, my response will be late.
    Thanks Jindon, This seems to be working really well, the only thing is when I add in extra rows like Trainee 06, 07, 08 etc it doesn't seem to be adding the new entries to the match results, is there a way to fix this so when table 1 and/or table 2 is expanded, the results (Table3) will add in the new entries?

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

    Re: VBA - How to Ignore array dimension mismatches? - move to next

    1) Don't full quote the post unless you really need to.
    The forum doesn' like it.

    2) It should run all the data in both tables.
    If it diesn't, need to see your workbook
    As I'm already out, I can only see it after I get back.

  16. #16
    Registered User
    Join Date
    11-07-2018
    Location
    Sydney Australia
    MS-Off Ver
    2016 Pro
    Posts
    74

    Re: VBA - How to Ignore array dimension mismatches? - move to next

    This is working really well, I found my mistake when I tested it a few more time.

    Thanks again Jindon, this will work perfectly.

    Cheers
    Last edited by Lee_of_Excel; 02-12-2020 at 07:19 PM.

  17. #17
    Registered User
    Join Date
    11-07-2018
    Location
    Sydney Australia
    MS-Off Ver
    2016 Pro
    Posts
    74

    Re: VBA - How to Ignore array dimension mismatches? - move to next

    Just 1 final question, if I move the tables, what do I modify in the code to recognise the new table position?

    I tried moving Table3 (results) but the results still publish in column L&M even when that range unnamed.

    Then I tried moving Table1 and Table 2 and it results in 'no matches'. I confirmed that the named ranges Table1, Table2 and Table3 are correct after moving and I can see in your code that it references the Table names, so I am puzzled with what I need to change in the code.

    I have attached the spreadsheet.

    Thanks
    Attached Files Attached Files
    Last edited by Lee_of_Excel; 02-12-2020 at 08:50 PM. Reason: Spreadsheet attached

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

    Re: VBA - How to Ignore array dimension mismatches? - move to next

    Change to
    Please Login or Register  to view this content.

  19. #19
    Registered User
    Join Date
    11-07-2018
    Location
    Sydney Australia
    MS-Off Ver
    2016 Pro
    Posts
    74

    Re: VBA - How to Ignore array dimension mismatches? - move to next

    Perfect! Thanks very much Jindon :-D

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

    Re: VBA - How to Ignore array dimension mismatches? - move to next

    Hello Lee_of_Excel,

    You may find this UDF I wrote for the Gale-Shapley algorithm useful. It works like an Excel formula. Each range is a table for the proposers and the acceptors. The result is a single 1-D array of the matches.

    Please Login or Register  to view this content.
    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!)

  21. #21
    Registered User
    Join Date
    11-07-2018
    Location
    Sydney Australia
    MS-Off Ver
    2016 Pro
    Posts
    74

    Re: VBA - How to Ignore array dimension mismatches? - move to next

    Thanks very much Leith, I'll try it out.

    Do you happen to have a spreadsheet example of this set up?

    Cheers
    Last edited by Lee_of_Excel; 02-13-2020 at 12:53 AM.

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

    Re: VBA - How to Ignore array dimension mismatches? - move to next

    Hello Lee_Of_Excel,

    Yes, I do. This is an example workbook. It has several tables with the UDF results along with the hand calculated results to verify the UDF is function correctly.
    Attached Files Attached Files

  23. #23
    Registered User
    Join Date
    11-07-2018
    Location
    Sydney Australia
    MS-Off Ver
    2016 Pro
    Posts
    74

    Re: VBA - How to Ignore array dimension mismatches? - move to next

    Quote Originally Posted by Leith Ross View Post
    Hello Lee_Of_Excel,

    Yes, I do. This is an example workbook. It has several tables with the UDF results along with the hand calculated results to verify the UDF is function correctly.
    This is great!! thanks very much Leith, I hadn't even considered a function, although I don't yet have the skills to write anything like this. Thanks again

    Cheers

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

    Re: VBA - How to Ignore array dimension mismatches? - move to next

    Hello Lee,

    You're welcome. Glad you like it. As far as I know, this is the only Gale-Shapley UDF written for Excel.

  25. #25
    Registered User
    Join Date
    11-07-2018
    Location
    Sydney Australia
    MS-Off Ver
    2016 Pro
    Posts
    74

    Re: VBA - How to Ignore array dimension mismatches? - move to next

    Hello again Jindon,

    Your code is working great, I just have a quick query with the logic.

    I ran the code on data that I had and it seemed to miss a couple of items, because the preferences weren't exact, Can I add a some code for it to match Trainee with Site when they have their preferences in any order, rather than just Trainee Preference x with Site Preference x?

    For Example:

    Trainee: 123879 had
    Preference 01: 443E7
    Preference 02: 303E7
    Preference 03: 863E7
    etc

    Site: 443E7 had
    Preference 01: 136170
    Preference 02: 123879
    Preference 03: 135111
    etc

    And the results:
    123879:303E7
    123879:863E7
    123879:5C3E7

    The results did not show the match 123879:443E7 Which was Preference01:Preference02? Can I add some code so it will pick up Preferences that are in different placing for example Trainee Preference 01 and Site Preference 02?

    I have attached my Workbook, where I have run the code
    Attached Files Attached Files
    Last edited by Lee_of_Excel; 02-16-2020 at 09:27 PM.

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

    Re: VBA - How to Ignore array dimension mismatches? - move to next

    Can you just try change 2 lines in bold and see if it works,
    1)
    Please Login or Register  to view this content.
    2)
    Please Login or Register  to view this content.

  27. #27
    Registered User
    Join Date
    11-07-2018
    Location
    Sydney Australia
    MS-Off Ver
    2016 Pro
    Posts
    74

    Re: VBA - How to Ignore array dimension mismatches? - move to next

    Quote Originally Posted by jindon View Post
    Can you just try change 2 lines in bold and see if it works,
    Thanks Jindon, It didn't seem to work,
    123879 still got the results:
    123879:303E7
    123879:863E7
    123879:5C3E7

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

    Re: VBA - How to Ignore array dimension mismatches? - move to next

    I see what you mean "Any order",
    Which Preference number should be in the result when P/N doesn't match?

  29. #29
    Registered User
    Join Date
    11-07-2018
    Location
    Sydney Australia
    MS-Off Ver
    2016 Pro
    Posts
    74

    Re: VBA - How to Ignore array dimension mismatches? - move to next

    For my use, Trainee would have priority, so if Trainee Preference:

    Trainee: 123879 had
    Preference 01: 443E7
    Preference 02: 303E7
    Preference 03: 863E7

    And Site: 443E7 has Trainee 123879 in any preference, this can match as first priority.

    followed by any others

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

    Re: VBA - How to Ignore array dimension mismatches? - move to next

    Hummm, this will pick up almost everything...
    Please Login or Register  to view this content.

  31. #31
    Registered User
    Join Date
    11-07-2018
    Location
    Sydney Australia
    MS-Off Ver
    2016 Pro
    Posts
    74

    Re: VBA - How to Ignore array dimension mismatches? - move to next

    Nice! thanks! this is looking good, I'll do some testing :-D, am I able to place the 'Site Code' in the results like before instead of the preference number?

    e.g.
    123879:Preference 6
    123879:Preference 1
    123879:Preference 2

    to
    123879:AF3E7
    123879:443E7
    123879:303E7

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

    Re: VBA - How to Ignore array dimension mismatches? - move to next

    Just try change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

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

    Re: VBA - How to Ignore array dimension mismatches? - move to next

    This will to show you the 3rd column of result "Preference(s)".
    I need to go out soon, so any changes will be late...
    Attached Files Attached Files

  34. #34
    Registered User
    Join Date
    11-07-2018
    Location
    Sydney Australia
    MS-Off Ver
    2016 Pro
    Posts
    74

    Re: VBA - How to Ignore array dimension mismatches? - move to next

    Thanks, that worked!

    I think I am still missing 1 last piece of code which will identify the final correct result.

    The correct result for Trainee:123879 should be site: 443E7 as the Trainee picked this as Preference 01 and The site picked the Trainee as Preference 02.

    The initial code gave the result: 123879:303E7 as they both had each other as Preference 02.

    The new code gives the result: 123879:AF3E7 as the first occurrence as The trainee preference for this site was Preference 07 and the Site has the trainee as Preference 01, But it also has all of the combinations, which I was looking for, but I am not sure how to rank/weight these in code to ensure that the Trainee gets their most preferable match, in this example 123879:443E7

    Any ideas?

  35. #35
    Registered User
    Join Date
    11-07-2018
    Location
    Sydney Australia
    MS-Off Ver
    2016 Pro
    Posts
    74

    Re: VBA - How to Ignore array dimension mismatches? - move to next

    Quote Originally Posted by jindon View Post
    This will to show you the 3rd column of result "Preference(s)".
    I need to go out soon, so any changes will be late...
    Thanks very much, I'll test it out.

    Cheers

  36. #36
    Registered User
    Join Date
    11-07-2018
    Location
    Sydney Australia
    MS-Off Ver
    2016 Pro
    Posts
    74

    Re: VBA - How to Ignore array dimension mismatches? - move to next

    Looks like its working quite well!

    I added a sheet 'Rank Matrix' and I am using your 3rd column results to index a rank matrix. I use 'text to columns' to split the 3rd column results into 2 columns on the rank matrix sheet (Trainee Preference # and Site Preference #) and then index against the matrix. It's very inelegant, but my vba skills aren't yet good enough to tidy it up.

    Then I added a 4th column on the match results beside your preference column to sort the results by matrix rank result.

    This solution seems to be working for all the tests I have done so far.

    Is there a way to have the text to columns, matrix index and sorting all done in vba also?

    Thanks again for your help, this will be a really useful tool.
    Attached Files Attached Files

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

    Re: VBA - How to Ignore array dimension mismatches? - move to next

    So the code is listing correct result?
    Please Login or Register  to view this content.

  38. #38
    Registered User
    Join Date
    11-07-2018
    Location
    Sydney Australia
    MS-Off Ver
    2016 Pro
    Posts
    74

    Re: VBA - How to Ignore array dimension mismatches? - move to next

    Quote Originally Posted by jindon View Post
    So the code is listing correct result?
    This is Fantastic!! thanks very much for your help Jindon. Yes it seems to be listing the correct results, I have a few lists from 2019 to go through to see if the results match, but so far everything looks really good.

    Cheers

+ 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] Reorder array columns dimension by another array
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 10-16-2018, 12:53 AM
  2. [SOLVED] how to declare 2 dimension array
    By mohan.r1980 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-23-2018, 04:21 AM
  3. add one dimension to array
    By shaykos in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 12-04-2015, 10:47 PM
  4. Excel: Sum each dimension of an Array
    By cmore in forum Excel Programming / VBA / Macros
    Replies: 42
    Last Post: 06-08-2015, 11:35 PM
  5. Does filling part of an array from a range re-dimension the array?
    By barryleajo in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-04-2011, 10:09 AM
  6. Array dimension
    By Henrietta Klaus in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-21-2006, 11:10 AM
  7. Mutli-dimensional Array to Single-Dimension Array
    By Blue Aardvark in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-15-2005, 05:05 AM

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