+ Reply to Thread
Results 1 to 5 of 5

Return Closest Matching Filename - Macro

  1. #1
    Registered User
    Join Date
    11-16-2012
    Location
    Rhode Island, USA
    MS-Off Ver
    Excel 2010
    Posts
    11

    Question Return Closest Matching Filename - Macro

    Hello!

    I have an odbc report that inserts data (product number) with trailing spaces. I currently have a macro that inserts an image from a specified file location based on the selected cell value. It works great when I manually enter a product number to run the macro off of as it obviously does not contain trailing spaces.

    I would like for the macro to search the specified file location based on the leading characters of the value in the selected cell and return the closest match possible. All with a msgbox that the exact file was not found but "the closest file is ...".

    For example, I need an image returned for product number 12345WHITE(+SPACES). If I only have a file named 12345, I'll need a message box = "12345WHITE not found. Inserting 12345" and insert the correspondingt image. If the folder also contains 12345WHI, it should attemp to return this file instead as it's the closest match.

    Can this be done?

    Thanks ahead to you wizards!

    E

  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: Return Closest Matching Filename - Macro

    Hello enidnunez,

    Please post your workbook and include more before and after examples. This will speed up developing a solution to your problem.

    To Post Your Workbook
    1. At the bottom right of the Reply window, Click the button Go Advanced
    2. At the top of the Your Message Window, in the first row of icons, Click the Paperclip icon.
    3. Click the Add Files button at the top right in the dialog box. This displays the File Manager dialog.
    4. Click the Select Files button at the bottom middle of the dialog.
    5. In the new window Find the file you want to upload, select it, and Click Open.
    6. You will now be back in the File Manager dialog. Click the bottom Middle button Upload File.
    7. Wait until the file has completely uploaded before you exit the File Manager dialog.

    File Manger Picture
    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
    Registered User
    Join Date
    11-16-2012
    Location
    Rhode Island, USA
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Return Closest Matching Filename - Macro

    Workbook is sensitive. Substitue attached.

    IF ITEM IS 4321GOLD, MACRO WILL RETURN IMAGE FILE 4321G.JPG AS OPPOSED TO 4321.JPG IF ITEM NOT FOUND
    IF ITEM IS JW005, MACRO WILL RETURN IMAGE FILE JW00.JPG AS OPPOSED TO JW006.JPG "
    IF ITEM IS 4321GOLD, MACRO WILL RETURN IMAGE FILE 4321WHITE.JPG (IF ITS THE NEXT CLOSEST MATCH).

    Please Login or Register  to view this content.
    Quote Originally Posted by Leith Ross View Post
    Hello enidnunez,

    Please post your workbook and include more before and after examples. This will speed up developing a solution to your problem.

    To Post Your Workbook
    1. At the bottom right of the Reply window, Click the button Go Advanced
    2. At the top of the Your Message Window, in the first row of icons, Click the Paperclip icon.
    3. Click the Add Files button at the top right in the dialog box. This displays the File Manager dialog.
    4. Click the Select Files button at the bottom middle of the dialog.
    5. In the new window Find the file you want to upload, select it, and Click Open.
    6. You will now be back in the File Manager dialog. Click the bottom Middle button Upload File.
    7. Wait until the file has completely uploaded before you exit the File Manager dialog.

    File Manger Picture
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    11-16-2012
    Location
    Rhode Island, USA
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Return Closest Matching Filename - Macro

    Can I use the Like Operator to accomplish part of this? If yes, how?

  5. #5
    Registered User
    Join Date
    11-16-2012
    Location
    Rhode Island, USA
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Return Closest Matching Filename - Macro

    I have used other methods to achieve intended results.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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