+ Reply to Thread
Results 1 to 5 of 5

Changing the colour of a cell based on PART of the text of the cell

  1. #1
    Registered User
    Join Date
    09-25-2014
    Location
    Sydney, Australia
    MS-Off Ver
    MS Office 2010
    Posts
    4

    Changing the colour of a cell based on PART of the text of the cell

    Hi folks,

    I have a Word document with cells that contain text like "Clear" or "Clear evidence" or "Bottom 30%", and I have a macro that finds cells with the text "Clear" or "Bottom" and colours them green or red respectively.

    However, the macro only works when that text is the entire contents of the cell. It won't colour "Clear evidence" green or "Bottom 30%" red.

    I've looked around for Word macros that might do this via wildcards, but they all seem to use the searchText command, which my current macro does not. I'm happy to switch, but this macro is the only way I've found to colour text (I found it on the web somewhere).

    Here is the macro as it currently stands:

    Please Login or Register  to view this content.
    Thanks for your help!
    Chris
    Last edited by FDibbins; 11-02-2014 at 09:06 PM.

  2. #2
    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,972

    Re: Changing the colour of a cell based on PART of the text of the cell

    Not too clued up on word, but in excel we would add wild cards to that. Something like...

    Case "*Bottom*"
    oCel.Shading.BackgroundPatternColor = RGB(247, 150, 70)
    Case "*Clear*"
    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

  3. #3
    Registered User
    Join Date
    09-25-2014
    Location
    Sydney, Australia
    MS-Off Ver
    MS Office 2010
    Posts
    4

    Re: Changing the colour of a cell based on PART of the text of the cell

    Quote Originally Posted by FDibbins View Post
    Not too clued up on word, but in excel we would add wild cards to that. Something like...

    Case "*Bottom*"
    oCel.Shading.BackgroundPatternColor = RGB(247, 150, 70)
    Case "*Clear*"
    Thanks for your reply, Ford. Unfortunately, this doesn't work - asterisks and so on are read as regular characters.

    When using the macro to find and replace, you can add the text: " .MatchWildcards = True". However, my understanding is that this does not work for the operation occurring here.

  4. #4
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Changing the colour of a cell based on PART of the text of the cell

    You could use:
    Please Login or Register  to view this content.
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  5. #5
    Registered User
    Join Date
    09-25-2014
    Location
    Sydney, Australia
    MS-Off Ver
    MS Office 2010
    Posts
    4

    Re: Changing the colour of a cell based on PART of the text of the cell

    Hi Paul,

    Thank you very much - that solved my problem.

+ 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] Changing the cell colour based on what is input in another cell.
    By MissMay in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 09-21-2013, 10:21 AM
  2. Changing the colour of a cell based on the colour of another cell
    By Pete2931 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-11-2012, 03:35 AM
  3. [SOLVED] changing cell A1 BACKGROUND colour IF CELL A3 for example contains text
    By robbyweston in forum Excel General
    Replies: 5
    Last Post: 03-05-2012, 12:55 PM
  4. Changing cell fill colour based on date in cell - Multiple rows
    By ExcelNewb2010 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-26-2010, 07:30 AM
  5. Changing Cell Fill Colour based on another cell value
    By MoonWeazel in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-02-2008, 10:15 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