+ Reply to Thread
Results 1 to 6 of 6

Replace string with strings from lookup table

  1. #1
    Registered User
    Join Date
    11-06-2014
    Location
    Germany
    MS-Off Ver
    2010
    Posts
    3

    Replace string with strings from lookup table

    My problem: I have several thousand article with American units and want to convert them using a comparison list.

    Example:
    Red Ball 5 inches long
    Ball Bearing 1/16 in long
    Black Block 1/16 in x 3/8 in
    Ball Bearing 11/16Inches long

    I have a list like this:
    1/16 1,6 mm
    1/16 in 1,6 mm
    1/16 Inch 1,6 mm
    1/16 inch 1,6 mm
    11/16 in 17,5 mm


    I need a macro that compares each column of one table against my conversion table and changes just the exact value.

    If I use this macro with xlWhole it does not find anything, if I use xlPart it replaces 11/11 with the 1/16 value. My Lookup table is around 700 entries.

    Please Login or Register  to view this content.
    I would appreciate any help.

    With kind regards, Markus
    Last edited by alansidman; 11-06-2014 at 08:57 AM.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,893

    Re: Replace string with strings from lookup table

    Code Tags Added
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html



    (Because you are new to the forum, I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Replace string with strings from lookup table

    So I would take a completely different approach to this problem then you are. I'm not saying what you're trying to do is wrong, just that I think this might be a better approach.

    First, I would get rid of the lookup table and just do math directly on each number. That's going to require a little bit of work, but not that much. Here's the process.

    1. Save your unconverted strings as a text file.
    2. Import that text file into excel (Data -->Get External Data --> From Text)
    3. When importing, choose Delimited by space
    4. Make sure your fraction column (what will be column C in your example data) is not formatted as general or date (text will do)
    5. Your import should look like this:
    sdr.png
    6. Now do a find and replace for anything in Column C that isn't a number (e.g. Replace "Inches" with "")
    7. Format Column C as Number
    8. Now run this code:
    Please Login or Register  to view this content.
    9. Yay, all your conversions are done (you could even set your ConRange to all the data, to pick up things like that 3/8 in.)
    10. Format the numbers as you wish.
    11. Do a find and replace for things like "in" to "mm"
    12. Recombine all the data if you want to by pasting into a word processor and replacing tabs with spaces.


    Looks like a lot of steps but I did it in less than a minute. I think that would be faster than 700+ searches even if you could get them set up perfectly. Plus this way, you don't have to keep track of every single conversion you need to do and add it to a conversion table.
    Last edited by walruseggman; 11-06-2014 at 10:09 AM.

  4. #4
    Registered User
    Join Date
    11-06-2014
    Location
    Germany
    MS-Off Ver
    2010
    Posts
    3

    Re: Replace string with strings from lookup table

    Thanks a lot for your help,
    but I need it to work with a lookup table, because I already have the table and I want to use this approach for solving some translations, and my source data is always a complete line not like Red in A1 and Ball in B2.

    With kind regards, Markus

  5. #5
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Replace string with strings from lookup table

    I wish you luck then. I'n not sure there will be an easy solution given your data set and approach, but I'd be interested to see it.

    If you post what your source data actually looks like (as you suggested it doesn't look like your example Red Ball, etc.), that would probably help a great deal.

    Edit: Just FYI, if you are using that lookup table, the entries all need to be ranked because you are using xlPart.

    So, for example, you need to list all of the 11/16 conversions before all of the 1/16 conversions, otherwise it will see 11/16 as 1"1/16" and output 1"1,6 mm" which is not what you want.

    Every single entry needs to be ranked like this, which for 700+ entries is quite a task.
    Last edited by walruseggman; 11-06-2014 at 11:43 AM.

  6. #6
    Registered User
    Join Date
    11-06-2014
    Location
    Germany
    MS-Off Ver
    2010
    Posts
    3

    Re: Replace string with strings from lookup table

    Hi, one example line looks like this.
    I need to translate some 1.000 products.
    My plan ist: extract all data between delimeters in a separate row. When all data is in A1 I run a macro to delete duplicates. Then apply macro to translate units. Then translate all lines in A1 to line B1. Then run same script that translated the units against A1 B1 as lookup table and replace all English text.

    Glass Angel Fish Pendant Necklace Earrings Set-Blue <li>Glass Fish Pendant On Blue Twine Chain With Lobster Claw Clasp</li><li>Matching Glass Dangle Charm Earrings With Shepherd Hooks</li><li>Pendant Measures Approximately: 1-5/8 Wide x 1-3/8 Tall x 3/8

+ 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] Lookup Table to Find/Replace Every Instance of a String (2/2)
    By Baghel in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-04-2013, 05:49 AM
  2. Replies: 12
    Last Post: 12-31-2012, 04:13 AM
  3. [SOLVED] How to lookup and replace string
    By singhabhijitkumar in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 09-18-2012, 04:43 AM
  4. [SOLVED] Find strings within cells and replace with string from a table
    By MMSte in forum Excel General
    Replies: 6
    Last Post: 05-14-2012, 12:22 PM
  5. search for multiple strings and replace them with the same string
    By aaron85 in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 07-14-2009, 04:24 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