+ Reply to Thread
Results 1 to 7 of 7

Insert text based on criteria match

  1. #1
    Registered User
    Join Date
    04-14-2010
    Location
    Ohio
    MS-Off Ver
    Excel 2007
    Posts
    10

    Insert text based on criteria match

    I'm trying to do some criteria automation on sheet activate but I just cannot get it to work. I have it automatically pulling matching rows from another sheet. What I want it to do is to insert a new column then from that insert some text if the column to the left of the new column matches some criteria.

    Please Login or Register  to view this content.
    The above code is supposed to look for the string "safety" within the cell range. Then if there is a match, insert "Safety" into the next column. Can someone help me figure out why it's not working? The insert column works correctly.

  2. #2
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    Re: Insert text based on criteria match

    Please Login or Register  to view this content.
    The above code uses excels built in compare function. The code is searching all of column "A" for the word safety and if it finds it, the word 'Safety' is put into column B. You can change the ranges to whatever you need.

    edit: Messed up one of the ranges. Should work now.
    Last edited by 111StepsAhead; 04-24-2012 at 08:54 AM.

  3. #3
    Registered User
    Join Date
    04-14-2010
    Location
    Ohio
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Insert text based on criteria match

    I tried implementing that into the existing code and also as a stand-alone function, however both do not seem to work. The F column cells remain empty even though safety is most definitely in the relative E cell. Is the function case-sensitive?

  4. #4
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    Re: Insert text based on criteria match

    Did you see the change I made to the range? I just ran the new code in my own workbook and it worked perfectly. It is not case sensitive so will pick up 'Safety' and 'safety'.

  5. #5
    Registered User
    Join Date
    04-14-2010
    Location
    Ohio
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Insert text based on criteria match

    I changed the range to match my needs. Can you check my file to see why it's not working? I put the code into a button. I removed all sensitive info from the spreadsheet.toolreport.xlsm

  6. #6
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    Re: Insert text based on criteria match

    You didn't use my updated code as I explained in the original submission.

    Also, put the code into the worksheet and not some module.

    Finally, your button should be an ActiveX command button. If the button is called

    CommandButton1

    then your Sub should be labeled Sub CommandButton1_Click().

  7. #7
    Registered User
    Join Date
    04-14-2010
    Location
    Ohio
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Insert text based on criteria match

    Thanks, that solved it!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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