+ Reply to Thread
Results 1 to 7 of 7

Conditional Formatting Rule to insert text into a blank cell if another cell contains text

  1. #1
    Registered User
    Join Date
    01-10-2016
    Location
    Texas
    MS-Off Ver
    2013
    Posts
    4

    Question Conditional Formatting Rule to insert text into a blank cell if another cell contains text

    Please forgive me if this is a duplicate post. I wasn't sure what to search for to see if this has been answered in the past.

    I have a spreadsheet that contains contact information and website URL for several thousand contractor companies. Header columns are: (A through I) "Company Name, Address, City, State, Zip Code, Phone, Email, and Website" I inserted a new blank column before "Company Name" and called it "Category" I would like to be able to categorize each company by the type of service that it provides.

    I would like to learn how to code a Conditional Format Rule or function that would add text to column "A" cells if the company name (Column B) contains text that I specify.

    Example: If Company Name in cell B1 contains "Roofing", then "Roofing" would be inserted into cell A1 in the "Category" column. Or if cell B457 contains "plumb" (partial match for plumber), then "Plumber" would be inserted in to A457.

    Any assistance with this will be greatly appreciated.

    Thanks in advance,

    Jack

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,798

    Re: Conditional Formatting Rule to insert text into a blank cell if another cell contains

    You can't do what you want with conditional formatting - that just changes some of the formatting in a cell depending on some condition. What you want is a conditional formula. You can use this formula in A1:

    =IF(COUNTIF(B1,"*Roofing*"),"Roofing",IF(COUNTIF(B1,"*plumb*"),"Plumber","none"))

    where the asterisks are the wildcard character. You can add other terms instead of "none", in a similar style.

    Hope this helps.

    Pete

  3. #3
    Registered User
    Join Date
    01-10-2016
    Location
    Texas
    MS-Off Ver
    2013
    Posts
    4

    Re: Conditional Formatting Rule to insert text into a blank cell if another cell contains

    Pete,

    This will work. Thanks.

    But I can foresee the amount of data in column A becoming very large and hard to manage by the time I add other categories.

    Would it be possible to keep the formula in Column A short by looking up the "IF(COUNTIF" value and Category name from lists in 2 predefined columns on a separate worksheet?

    Something like: =IF(COUNTIF(B1,"{column A cell range on separate worksheet}"),"{column B cell range on separate worksheet}","none")). VLookup maybe?

    Example: On worksheet 2, column A will contain search strings (A1=*roof*, A2=*plumb*, A3=*heat*) and column B would have category names (B1=Roofing, B2=Plumber, B3=HVAC). Lets say that if any part of cell B1 on worksheet 1 was to match cell A3 (*heat*) on worksheet 2, then cell A1 on worksheet 1 would equal whatever value is in cell B3 (HVAC).

    This would allow me to keep the formula in all column A cells consistent and short and allow me to add more search strings & categories easily.

    This makes sense in my mind. I hope you are able to understand it.

    Thanks,

    Jack

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,946

    Re: Conditional Formatting Rule to insert text into a blank cell if another cell contains

    If you can construct a table (1 column?) with a list of all the names you have, you could probably use INDEX/MATCH to pull in what you want.

    Will the referenced column (B?) always just contain that 1 work, or will it be part of a larger test string?
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  5. #5
    Registered User
    Join Date
    01-10-2016
    Location
    Texas
    MS-Off Ver
    2013
    Posts
    4

    Re: Conditional Formatting Rule to insert text into a blank cell if another cell contains

    The following works, and I am thankful that it was shared, but it would be hard to manage when I add all of the construction categories to the formula and would be a lot of duplicated data in all of the cells in column A.

    =IF(COUNTIF(B1,"*roof*"),"Roofing",IF(COUNTIF(B1,"*plumb*"),"Plumber","none"))

    --

    The VLookup function below also works if the Company Name in cell "B2" is an exact match.

    =VLOOKUP(B2,Categories!A1:B5,2,0)

    --

    Is it possible to combine the 2 functions that would do partial match of text in column "B"?

    I would like to be able to do partial matches because some companies use variations of a category name like "JJ Roofing" or "LA Roofers". On a 2nd worksheet named "Categories", I have 2 columns; column "A" contains partial names of categories with wild cards and column "B" contains the actual proper name of the categories.

    I really appreciate everyone's input.

    Jack
    Attached Images Attached Images

  6. #6
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,481

    Re: Conditional Formatting Rule to insert text into a blank cell if another cell contains

    Assuming sheet Catergories cell A1:B5 contain criteria table

    In A2 current sheet:

    Please Login or Register  to view this content.
    P/S: Cell A1 sheet cartergories contains criteria like this: "roof" (without "*")
    Last edited by bebo021999; 01-11-2016 at 01:22 AM.
    Quang PT

  7. #7
    Registered User
    Join Date
    01-10-2016
    Location
    Texas
    MS-Off Ver
    2013
    Posts
    4

    Re: Conditional Formatting Rule to insert text into a blank cell if another cell contains

    When I enter your formula and press enter, it wants to open a file. The title bar has, "Update Values: Categories". I don't know what file it would be looking for. Am I still doing something wrong?

    Please assist,

    Jack

+ 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] How to insert blank row above a cell containing specific text
    By Excelfail in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-23-2019, 09:19 AM
  2. Replies: 6
    Last Post: 04-15-2015, 10:25 PM
  3. insert text and a cell value in conditional formatting
    By alexcol in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-09-2014, 07:21 PM
  4. Replies: 3
    Last Post: 06-25-2013, 04:41 AM
  5. [SOLVED] Insert blank row after each cell that contains text in column A
    By anrichards22 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-14-2013, 03:10 AM
  6. [SOLVED] Using more than 1 rule in one cell in conditional formatting
    By cadamhill in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-15-2012, 08:25 PM
  7. How to insert blank row below a cell containing specific text
    By Lmsloman in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 05-15-2012, 02:59 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