+ Reply to Thread
Results 1 to 11 of 11

Change the colour of single word in text string based on another cell value

  1. #1
    Forum Contributor
    Join Date
    06-25-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2003
    Posts
    179

    Change the colour of single word in text string based on another cell value

    Hi All,

    I'm really struggling to find a solution to this so some pointers would be great.

    I have a words in cell C3 and C4 and some large strings that appear in cells F8 through F220. I'm trying to produce a piece of code that basically looks for the words in C3 and C4 and highlights them in F8 through F220 in red.

    Whats the easiest way to go about doing this?

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Change the colour of single word in text string based on another cell value

    Hi,

    Do both words in C3 & C4 have to be present?
    What are you trying to highlight in F8:F220? Any cell that contains one (or both) words or just the word in the bigger string.

    If the former then you don't need a macro. You can use an =MATCH() function in an adjacent column (say G) to identiify where F contains the words and use conditional formatting to paint the relevabt cells some appropriate colour.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Contributor
    Join Date
    06-25-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2003
    Posts
    179

    Re: Change the colour of single word in text string based on another cell value

    Hi Thanks for responding.

    No both words don't have to be present just either or and ideally if i have a string in F8 for example that looks like this.
    "The cat in the hat" and the reference in C3 is hat. I'd like the cell in f8 to look like "The cat in the hat" and any cell in the range F8:F220 that word should have that specific word highlighted.

  4. #4
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Change the colour of single word in text string based on another cell value

    Hi

    How about this?
    Please Login or Register  to view this content.
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

  5. #5
    Forum Contributor
    Join Date
    06-25-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2003
    Posts
    179

    Re: Change the colour of single word in text string based on another cell value

    Hi thanks for the response, i can't seem to get it to function though.
    I changed the Row count to 8 to match my data set as it starts in F8. However, when i run it it doesn't change the colour of the word in question. For example in a test data set. I set C3 to cats and F8:F16 to All the cats and none of the cats were highlighted. I can't quite workout why this wouldn't work.

  6. #6
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Change the colour of single word in text string based on another cell value

    Try in this way..


    Please Login or Register  to view this content.

  7. #7
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Change the colour of single word in text string based on another cell value

    Fotis' code should have worked as it was posted. I'd prefer to store a couple of the calculations rather than redoing them each time:

    Please Login or Register  to view this content.
    but it shouldn't matter particularly.
    Remember what the dormouse said
    Feed your head

  8. #8
    Forum Contributor
    Join Date
    06-25-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2003
    Posts
    179

    Re: Change the colour of single word in text string based on another cell value

    Hi still cant get it to run and i'm not sure why. Everything is as it should be. I dont know if its because the string is pulled in from a vlookup which might cause the problem. But then again i can't get it to run on a test sheet where i've typed the values into C3 and F8:F16

  9. #9
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Change the colour of single word in text string based on another cell value

    Sample using a formula to get value in C3 is attached.
    Attached Files Attached Files

  10. #10
    Forum Contributor
    Join Date
    06-25-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2003
    Posts
    179

    Re: Change the colour of single word in text string based on another cell value

    hi i found the issue with my sheet my data in F8:F16 is a vlookup of data on another sheet. I can get Fotis's sheet to work when the data in F8:F16 is just copied as values but the moment i swap it out for data that references the adjacent cell containing the long text string it stops working.

  11. #11
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Change the colour of single word in text string based on another cell value

    It's not possible to format part of the result of a formula as a different colour. You would have to replace the formulas with actual values to do it.

+ 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. Macro to change colour of cell based on finding a specific word in the cell
    By Shelby761 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-24-2014, 09:46 AM
  2. Change fill colour based on text in a cell
    By Doogles10 in forum Excel Programming / VBA / Macros
    Replies: 25
    Last Post: 07-01-2013, 03:30 PM
  3. Macro to Change the colour of cell based on text
    By rakeshplb in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-26-2009, 04:17 AM
  4. Using FindNext to Quantify Change in 2 Single-Word String Lists
    By Veter in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-05-2008, 12:07 PM
  5. Change text Colour based a another cell
    By darkan9el in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-13-2007, 07:41 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