+ Reply to Thread
Results 1 to 5 of 5

Match method always returns false (comparing cell's value to a list)

  1. #1
    Registered User
    Join Date
    04-15-2013
    Location
    Dert
    MS-Off Ver
    Excel 2007
    Posts
    10

    Match method always returns false (comparing cell's value to a list)

    Hello everyone,

    Here is my situation. I have in my program :
    - a list of values of any kind (numbers, strings, etc.) in my column C (most specifically : "C2:C16")
    - a list with names of cities (in "G21:G25")

    I want to create a sub to compare each content from my column C ("C2:C16") with each string from ("G21:G25"). If there is a match, I want to write the value "10" to the corresponding row of the active cell but in the column G, if no match, then it will write 0.

    So for example, if C8 content is "Paris" and "Paris" is also among G21:G25, then G8 is gonna be 10.
    If C9 content is "1889" and there is no such value among G21:G25, then G9 is gonna be 0.

    Here is my code and problem. So the problem is, it's always returning "false" even if there are some matches between my C list and my G list. I guess one problem might come from IsNumeric (because not every content is numeric) but I tried IsObject, IsArray, whatever was suggested and it always returns false.

    Please Login or Register  to view this content.
    Thanks in advance for your help!

    EDIT : protoype1.xlsm

    Phalanx
    Last edited by Phalanx_; 04-18-2013 at 02:26 AM.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,607

    Re: Match method always returns false (comparing cell's value to a list)

    Attach a sample workbook. Make sure there is just enough data to make it clear what is needed. Include BEFORE/AFTER sheets if needed to show the process you're trying to complete or automate. Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    04-15-2013
    Location
    Dert
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Match method always returns false (comparing cell's value to a list)

    Hi protonLeah, I attached my file, please let me know if it's working, it's my first file to attach.
    There are only two methods in the "module" now, the relevant one is called "probaCity()". Thanks for your time !

  4. #4
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,607

    Re: Match method always returns false (comparing cell's value to a list)

    There's nothing wrong with your vb code. The cities in the city list have some ending spaces so the match returns false. I don't know where the list is coming from but the TRIM function may help. Also your calculation for the length of the word is off.
    To extract word I modified your formula to:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    num chars...:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    and length word:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    04-15-2013
    Location
    Dert
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Match method always returns false (comparing cell's value to a list)

    Thanks a lot protonLeah, it was indeed caused by the spaces! The Trim function solved this; working well now. As for the length of the words, I am putting some order in it now. Have a great day !

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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