Results 1 to 5 of 5

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

Threaded View

  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:

    Sub TestINTERNAL(VariableName As Document)
        Dim oTbl As Table
        Dim oCel As Cell
        Dim oRng As Range
        For Each oTbl In ActiveDocument.Tables
    For Each oCel In oTbl.Range.Cells
                Set oRng = oCel.Range
                oRng.End = oRng.End - 1
                Select Case oRng.Text
                Case "Bottom"
                    oCel.Shading.BackgroundPatternColor = RGB(247, 150, 70)
                Case "Clear"
                    oCel.Shading.BackgroundPatternColor = RGB(155, 187, 89)
                End Select
                Next
                Next
    End Sub
    Thanks for your help!
    Chris
    Last edited by FDibbins; 11-02-2014 at 09:06 PM.

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