+ Reply to Thread
Results 1 to 10 of 10

VBA to search cell containing specific text and return common value

  1. #1
    Registered User
    Join Date
    06-25-2014
    Location
    Singapore
    MS-Off Ver
    2007/2010
    Posts
    55

    VBA to search cell containing specific text and return common value

    Hi I am a amateur into VBA Excel. Not doubt wasnt easy for me but i tried to use this forumlae for work.

    Thus, would like to seek the help on the following work example which can be replaced by a VBA.
    My intention is to expand the category to go beyond more than 7 types with the help of a VBA to formulae by cell:

    Column "A" - Highlights of work issue
    Column "B" - Category with formulae of "=IF(ISNUMBER(SEARCH("bubble",A2)),"Bubble on Tape",IF(ISNUMBER(SEARCH("particle",A2)),"Particle on Tape",IF(ISNUMBER(SEARCH("stain",A2)),"Stain on Tape",IF(ISNUMBER(SEARCH("u-shape",A2)),"U-shape bubble on Tape",IF(ISNUMBER(SEARCH("offset",A2)),"Tape offset",IF(ISNUMBER(SEARCH("winkled",A2)),"Tape Winkled","Others"))))))"

    Attached is the excel.Work Example01.xlsx

    Any form of help and assistance is greatly appreciated!

    Thanks & Regards,
    Hate0lif3

  2. #2
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: VBA to search cell containing specific text and return common value

    See the use of VLOOKUP function
    In you example
    C2=VLOOKUP(A2,$E$2:$F$16,2,0)
    where $E$2:$F$16 is the table
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    05-21-2014
    Posts
    92

    Re: VBA to search cell containing specific text and return common value

    This is not VBA code, but it should be able to get past your 7 item limit:

    Work Example01-moni.xlsx

    Sheet2 has a table of the search terms and corresponding categories indexed (B Column = index, C column = search term, D column = Category) (table= Sheet2!$B$3:$D$9).

    index search Category
    1 bubble Bubble on Tape
    2 particle Particle on Tape
    3 stain Stain on Tape
    4 u-shape U-shape bubble on Tape
    5 offset Tape offset
    6 winkled Tape Winkled
    0 #N/A Others

    (sorry, I haven't figured out how to do the table coding efficiently yet)

    This table can be updated with more items by just adding in new rows above the bottom 0 indexed item "Others".

    For the formula, I used the following:

    Please Login or Register  to view this content.
    Does this help?
    Last edited by Monimonika; 06-29-2014 at 10:49 AM.

  4. #4
    Registered User
    Join Date
    06-25-2014
    Location
    Singapore
    MS-Off Ver
    2007/2010
    Posts
    55

    Re: VBA to search cell containing specific text and return common value

    Hi PCI & Monimonika,

    Thanks for the help!
    The solutions provided are definitely different from what I could have use for this work example.

    By any chance, if my intention is to modify the example and automated it with a VBA script. How would I be able to do so?
    Given that I would like to search certain text within a cell of column "A" and return the key word to match the category names. And, output the category names into the cells of column "B".
    In all, the data in both columns "A" and "B" will always increased over time.

    Once again, any small or big help is greatly appreciated!

    Regards,
    Hate0lif3

  5. #5
    Registered User
    Join Date
    06-25-2014
    Location
    Singapore
    MS-Off Ver
    2007/2010
    Posts
    55

    Re: VBA to search cell containing specific text and return common value

    Ops deleted due to dble reply.

  6. #6
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: VBA to search cell containing specific text and return common value

    Try next code
    Assuming
    F1:G7 has the category table
    "bubble" "Bubble on Tape"
    "particle" "Particle on Tape"
    "stain" "Stain on Tape"
    "u-shape" "U-shape bubble on Tape"
    "offset" "Tape offset"
    "winkled" "Tape Winkled"

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by PCI; 06-29-2014 at 11:47 AM. Reason: Code modified

  7. #7
    Registered User
    Join Date
    05-21-2014
    Posts
    92

    Re: VBA to search cell containing specific text and return common value

    Quote Originally Posted by PCI View Post
    Please Login or Register  to view this content.
    Hi PCI,

    Just tried out your code and found an unusual glitch that may or may not be significant depending on how hate0lif3 will be using it. Or maybe it's a feature?

    Namely, the script stops working for subsequent rows if the row in Column A at the bottom of the list is not filled in first.

    Example: If A20 is the last highlight item, inputting text into A22 does not fill in B22.

    If the skipped A21 is then inputted with text, the script fills in for B21.

    However, re-inputting text for A22 and onward still does not fill in for B22 and onward.

    To get the script working again, the text in A22 (as well as all subsequent cells) has to be deleted completely (Enter key pressed) and then new text inputted.

    This glitch only occurs in the above very unusual usage, so most likely it is not worth worrying about. But I wanted to point it out just in case.

  8. #8
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: VBA to search cell containing specific text and return common value

    Monimonika,
    Thank you? YOUR comment is very important.
    But curiously I'm not able to reproduce the issue.
    How the macro is working:
    For all cells from A2 to the last cell with data in column A
    A check is done to see if exist a category
    Therefore if it exist an empty cell before the last one it is treated normally and the category others is written
    See the file attached.
    If, nevertheless, it is not what you got, could you please send your file.
    PCI
    Attached Files Attached Files
    Last edited by PCI; 06-29-2014 at 04:13 PM. Reason: typo

  9. #9
    Registered User
    Join Date
    05-21-2014
    Posts
    92

    Re: VBA to search cell containing specific text and return common value

    First, I apologize that I got the columns wrong in my post. Instead of column B, I meant column C was not being filled. I now realize because of the above, what I was actually seeing was Excel 2010 auto-filling hate0lif3's own formula in column C.

    I was under the impression that your macro was automatically detecting and filling in the categories, but did not realize that the macro had to be started manually (which kind of defeats the purpose).

    So, in order to make this truly automatic, I tweaked your code a teensy little bit (read: I changed one single line):

    Please Login or Register  to view this content.
    I right-clicked worksheet "Sheet1", chose "View Code...", and pasted the above code inside.

    Work Example01(automated).xlsm
    Last edited by Monimonika; 06-29-2014 at 06:50 PM.

  10. #10
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: VBA to search cell containing specific text and return common value

    OK, why not.
    I'm not positive to have macro launched automatically, let's Hate0lif3 decide.
    - Battle without fear gives no glory - Just try

  11. #11
    Registered User
    Join Date
    06-25-2014
    Location
    Singapore
    MS-Off Ver
    2007/2010
    Posts
    55

    Re: VBA to search cell containing specific text and return common value

    Thanks PCI and Monimonika!

    :P I prefer PCI method as I need to integrate as another sub function for my work vba!

+ 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. Replies: 4
    Last Post: 08-15-2013, 09:50 AM
  2. Search for specific value in a row, then return content og adjacent cell
    By linaudio in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-20-2013, 09:11 AM
  3. [SOLVED] Formula to search a column for a specific value, and return the value in the next cell
    By TimothyD in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-26-2013, 12:02 AM
  4. [SOLVED] search for specific text in a file and return a value to a cell based on the results
    By JJGF in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 01-03-2013, 07:00 PM
  5. Replies: 3
    Last Post: 06-20-2012, 07:16 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