Consulting

Results 1 to 5 of 5

Thread: Solved: Change font colour when string found

  1. #1
    VBAX Regular
    Joined
    Sep 2004
    Posts
    61
    Location

    Solved: Change font colour when string found

    Hi forum,

    I have a simple spreadsheet that has combinations of text and numbers. I want to change the font to Red & Bold on a certain word whereever it is found.

    The spreadsheet changes often, and the word may be by itself, at the start / end or any part of a description.

    I have attached a spreadsheet with a sample of the worksheet, and also a sample of how I need the final result to be. My poor attempt at the code is also there.

    Any help is greatly appreciated.

    Regards
    Koala
    Attached Files Attached Files

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Sub ColourWord()
    Const SearchWord As String = "HELP"
    Dim cell As Range
    Dim pos As Long

    For Each cell In ActiveSheet.UsedRange

    pos = InStr(cell.Value, SearchWord)
    If pos > 0 Then

    With cell.Characters(pos, Len(SearchWord)).Font

    .ColorIndex = 3
    .Bold = True
    End With
    End If
    Next cell
    End Sub[/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Sep 2004
    Posts
    61
    Location
    Thank you XLD,

    That works perfect.

    Kind Regards
    Koala

  4. #4
    VBAX Regular
    Joined
    Sep 2004
    Posts
    61
    Location

    I thought it was ok but its not.

    XLD,

    My appologies,

    I thought your response worked fine, as I only ran it on sample data.

    The actual data values that I wish to have coloured are linked from different sheets, and the code only works where the criteria word is by itself.

    I have updated and attached my spreadsheet again, and you can see where it works fine on the "Original" sheet, but not on the the "Data" sheet.

    Are you able to assist further.

    Regards
    Koala
    Attached Files Attached Files

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I don't think that can be done. The cell does not actually include the word Help, it has a formula that returns that text, and the cell does not inherit the sub-formatting of the original cell.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •