+ Reply to Thread
Results 1 to 5 of 5

Find partial text in cell and assign variable a value if found

  1. #1
    Forum Contributor
    Join Date
    07-03-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    139

    Find partial text in cell and assign variable a value if found

    I am trying to search for specific words in a cell, and if found, I want a variable assigned a value "1", if not found then that variable gets a 0. My code is listed below. This runs without error, HOWEVER it does not change my values for the variables, in the msgbox at the end it still shows all 0's even though the text I am searching for is present in the cells.

    if I STEP through the code in VBA it is ignoring the ELSE for each of the IF THEN statements?

    thoughts?

    Please Login or Register  to view this content.

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Find partial text in cell and assign variable a value if found

    lday75,

    Instead of using worksheetfunctions to get see if there is a string within a string, try using the VBA method InStr:

    Please Login or Register  to view this content.
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Forum Contributor
    Join Date
    07-03-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    139

    Re: Find partial text in cell and assign variable a value if found

    tigeravatar - This is producing the same results. Sorry, but thank you for the quick reply.

  4. #4
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Find partial text in cell and assign variable a value if found

    lday75,

    Works just fine for me when I tested it. Can you provide an example workbook that explains what results you're looking for?

    To best describe or illustrate your problem you would be better off attaching a dummy workbook, the workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook.

    If needed supply a before and after sheet in the workbook so the person helping you can see what you are trying to achieve.
    To attach a file, click the "Go Advanced" button and then click the paperclip icon to open the Manage Attachments dialog.

  5. #5
    Forum Contributor
    Join Date
    07-03-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    139

    Re: Find partial text in cell and assign variable a value if found

    I was able to get this resolved by using a COUNTIF statement and this is producing exactly what I was looking for. Code below

    Please Login or Register  to view this content.
    In a nut shell, what I need is for this code to recognize what vendors are listed on the Prod Rec sheet, and based off of the values of the Flg variables load one of 5 different userforms it gets rather complex after this section :>)

    Thanks again for your help though, I appreciate the replies.

+ 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