+ Reply to Thread
Results 1 to 10 of 10

User Defined function for comparing 2 array and return approximate match

  1. #1
    Registered User
    Join Date
    05-05-2018
    Location
    Dubai, UAE
    MS-Off Ver
    2016
    Posts
    5

    User Defined function for comparing 2 array and return approximate match

    Hey, please help

    I need to compare 2 arra

    First having titles like:
    Manager-accounts
    Manager - Sales
    Officer - Accounts
    Officer - HR
    Supervisor-

    Second having (this is not set in stone)
    Manager
    Officer
    Supervisor
    etc.

    I want to compare the 2 array and then return the common term from the second array.
    Result needs to be

    Manager
    Manager
    Officer
    Officer
    Supervisor


    I tried this code in module

    Please Login or Register  to view this content.
    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #3 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer

    This only returns one cell at a time. Please help to make it or help me with a new code to compare array and return the second array.

    Please Help!!


    Arun Menon
    Last edited by 6StringJazzer; 05-05-2018 at 08:31 AM.

  2. #2
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: User Defined function for comparing 2 array and return approximate match

    Please give an example of data (manager, officer, etc., data layout in columns and rows), not original of course, and the expected result.
    Last edited by mjr veverka; 05-05-2018 at 04:45 PM.

  3. #3
    Registered User
    Join Date
    05-05-2018
    Location
    Dubai, UAE
    MS-Off Ver
    2016
    Posts
    5
    Quote Originally Posted by porucha vevrku View Post
    Please give an example of data (manager, officer, etc., data layout in columns and rows), not original of course, and the expected result.
    Thank you for helping me out.. I have attached a file with List on the left and a sample compare list on the right column. The title is a part of a big list. I hope this will give you an idea of the data set.

    Many thanks in advance.
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    05-05-2018
    Location
    Dubai, UAE
    MS-Off Ver
    2016
    Posts
    5
    Quote Originally Posted by porucha vevrku View Post
    Please give an example of data (manager, officer, etc., data layout in columns and rows), not original of course, and the expected result.
    Sorry the I forgot to put in the output column. Please find attached.

    The compare list might be another page, so user-defined (titlelist,array to compare) or something in that line I am hoping to make.

    Thanks again.
    Attached Files Attached Files

  5. #5
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: User Defined function for comparing 2 array and return approximate match

    Is really the output array supposed to have multiple duplicate entries (manager, manager, manager, ..., officer, officer, officer, officer, etc.) ?

  6. #6
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: User Defined function for comparing 2 array and return approximate match

    OK, try it, but this applies to this data layout, as in the attachment:
    Look at the notes in the code (e.g.: For duplicates 'Exit For' commented / for unique specimens 'Exit For' uncommented)

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

  7. #7
    Registered User
    Join Date
    05-05-2018
    Location
    Dubai, UAE
    MS-Off Ver
    2016
    Posts
    5

    Re: User Defined function for comparing 2 array and return approximate match

    Thank you the reply and help.

    This i think maybe because I am not doing it right, it does not run through the entire compare list for each title cell. Plus it seems to match corresponding cell or i.e. a1 to f(i), then a2 to f(i)+1. Can you help me to tweak that please? and is there anyway we could let to make this as a user defined function { compare (list, compare list) } so that it can take in the compare list as a selection when working?? Just a thought if you can help, but the above code is a huge help if you can help to fix it to run for entire compare list for each title.

    Capture.PNG

    Thanks for the help.

    Arun

  8. #8
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: User Defined function for comparing 2 array and return approximate match

    1. If you are deleting some cell in "small input range", then value of this cell is "" (empty string, "nothing", but this is also a "value"), then in the structure:
    Please Login or Register  to view this content.
    we have: "If some_value Like "*" Then", which causes the empty value to be entered to the array variable (which is then entered into the worksheet).

    It's easy to prevent it, but why are you actually deleting data in this area ?

    2. You will never know how many cells will be with the result (unless you count them before), so you will be forced to mark more cells than necessary.

    3. With the "unique" option you will have to select an output area equal to the "small input area"

    4. With the "duplicate" option you will have to select an output area equal to the "bigger input area"

    5. The formula will be entered as an array, i.e. with CSE (ctrl+shift+enter) key combination

  9. #9
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: User Defined function for comparing 2 array and return approximate match

    Ok, try:
    Please Login or Register  to view this content.
    Form of the formula (in your case):

    compare1Darray("smaller range","bigger range",unique)

    1. For "unique" values
    =compare1Darray(F2:F28,A2:A106)
    or
    =compare1Darray(F2:F28,A2:A106,"True")

    2. For "duplicate" values
    =compare1Darray(F2:F28,A2:A106,"False")

  10. #10
    Registered User
    Join Date
    05-05-2018
    Location
    Dubai, UAE
    MS-Off Ver
    2016
    Posts
    5

    Re: User Defined function for comparing 2 array and return approximate match

    Thank you porucha vevrku. Will try that.

+ 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. how return an array of user defined datatype
    By whburling in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-26-2017, 03:04 PM
  2. Replies: 4
    Last Post: 03-31-2017, 05:49 AM
  3. Passing an array in a user defined function
    By Peter M in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-16-2013, 01:15 AM
  4. User-Defined Function & Array Formulas
    By faithcmbs9 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-01-2013, 05:46 PM
  5. Creating An Array to Be Used In a User Defined Function
    By ashleys.nl in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-23-2012, 08:17 PM
  6. user defined function using Array
    By Dennisli2000 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-18-2007, 02:00 PM
  7. [SOLVED] How to get a return value from a user defined function
    By Glen Mettler in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-25-2005, 12:05 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