+ Reply to Thread
Results 1 to 9 of 9

Macro to lookup string in a cell

  1. #1
    Registered User
    Join Date
    07-21-2014
    Location
    Seattle, USA
    MS-Off Ver
    2010
    Posts
    7

    Macro to lookup string in a cell

    Hello,

    I need a macro to lookup a string in a cell against a column on another worksheet. Attached is the sample spreadsheet of what I am looking for. "Sheet 2" has the master data or the column against which I want to do a look up. "Sheet 1, Column A" is what I want to look up and "Sheet 1, Column B" is the output which is "Yes" when the string is present in the master data and "No" when it is not.

    So, for example in the attached spreadsheet, "Sheet 1, cell (2,1)" = "Apple Iphone 7 USA". Now this string contains "Apple" which is present in "Sheet 2, Column A" so the output will be "Yes". Similarly, "Sheet 1, cell (4,1)" = "Motorola Razr USA Oppo China", now none of these words is present in the "Sheet 2, Column A", hence the output is "No".

    Thanks for all the help and let me know if you have any questions.
    Attached Files Attached Files

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

    Re: Macro to lookup string in a cell

    Try
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    07-21-2014
    Location
    Seattle, USA
    MS-Off Ver
    2010
    Posts
    7

    Re: Macro to lookup string in a cell

    Thank you. That works perfectly.
    Since I am trying to learn VB, can you please explain the logic here?

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

    Re: Macro to lookup string in a cell

    In short, using Regular Expression to evaluate if the string in sheet2 appears to sheet1 cells in col.A.

    I guess this is easier to understand, but not quite the same.
    Difference is that Regular Expression will only find independent word like Apple, but Like operator also matches to Apples. etc.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    07-21-2014
    Location
    Seattle, USA
    MS-Off Ver
    2010
    Posts
    7

    Re: Macro to lookup string in a cell

    Thanks a lot. Final question: What if i want output in column E instead of column B?

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

    Re: Macro to lookup string in a cell

    Better change whole code to store col.A and col.E separately, but easy change would be
    1)
    Please Login or Register  to view this content.
    2)
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    07-21-2014
    Location
    Seattle, USA
    MS-Off Ver
    2010
    Posts
    7

    Re: Macro to lookup string in a cell

    Sorry, I forgot to clarify.
    Can you suggest changes in the second code you provided to get output in column E?

    The first code is difficult to understand.
    Thank you.

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

    Re: Macro to lookup string in a cell

    2) replace all a(i, 2) with a(i, 5)

  9. #9
    Registered User
    Join Date
    07-21-2014
    Location
    Seattle, USA
    MS-Off Ver
    2010
    Posts
    7

    Re: Macro to lookup string in a cell

    Awesome and thanks.
    I hope i can develop skills like you.

+ 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] Formula or Macro, match string,from 1 cell to a column,String use dash
    By david gonzalez in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-07-2013, 06:03 PM
  2. Lookup for Code that Corresponds to Part of string of text in a Cell
    By brandnew22 in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 08-06-2013, 07:33 PM
  3. Vlookup needed to give value lookup value is a string within a cell.
    By CFlack8472 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-23-2012, 01:20 PM
  4. Search lookup array to find lookup value contained within text string
    By Cookstein2 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-02-2011, 09:42 AM
  5. Replies: 6
    Last Post: 06-16-2010, 01:18 PM
  6. A Macro to replace a string in a cell with a string from another cell???
    By Plica05 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-16-2005, 04:23 AM

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