+ Reply to Thread
Results 1 to 3 of 3

Custom format text

  1. #1
    coco
    Guest

    Custom format text

    Good morning all,
    I have in column E, from cell E1 to E300, text information all over black
    color.
    Each cell has about 50 characters.
    I want to search all these cells for the string ZZZ and if it find the
    string then change ZZZ color from black to red. Only ZZZ needs to be change
    to red and not the whole text in the cell.

    Thanks

    Coco


  2. #2
    sebastienm
    Guest

    RE: Custom format text

    Hi,
    The following code changes the color of the 1st instance of the
    search-string in each cell of the current selection.
    '----------------------------------------------------------
    Sub test()
    Dim rg As Range, cell As Range
    Dim txt As String, searchFor As String
    Dim pos As Long, lenSearch As Long

    '-------- CHANGE HERE ---------------------
    Set rg = Selection
    searchFor = "zzz"
    '-----------------------------------------------

    lenSearch = Len(searchFor)
    For Each cell In rg.Cells
    If Not rg.HasFormula Then 'If not formula
    txt = cell.Text
    pos = InStr(txt, searchFor)
    If pos > 0 Then 'Set Color
    cell.Characters(pos, lenSearch).Font.Color = vbRed
    End If
    End If
    Next

    End Sub
    '-----------------------------------------------------------
    To modify the color for all instances within a cell, modify the code within
    the:
    If Not rg.HasFormula Then
    to loop within the string.

    --
    Regards,
    Sébastien
    <http://www.ondemandanalysis.com>


    "coco" wrote:

    > Good morning all,
    > I have in column E, from cell E1 to E300, text information all over black
    > color.
    > Each cell has about 50 characters.
    > I want to search all these cells for the string “ZZZ” and if it find the
    > string then change ZZZ color from black to red. Only ZZZ needs to be change
    > to red and not the whole text in the cell.
    >
    > Thanks
    >
    > Coco
    >


  3. #3
    coco
    Guest

    RE: Custom format text

    This was fast.
    perfect!!!, it works fine
    Thanks you Sébastien

    Coco

    "sebastienm" wrote:

    > Hi,
    > The following code changes the color of the 1st instance of the
    > search-string in each cell of the current selection.
    > '----------------------------------------------------------
    > Sub test()
    > Dim rg As Range, cell As Range
    > Dim txt As String, searchFor As String
    > Dim pos As Long, lenSearch As Long
    >
    > '-------- CHANGE HERE ---------------------
    > Set rg = Selection
    > searchFor = "zzz"
    > '-----------------------------------------------
    >
    > lenSearch = Len(searchFor)
    > For Each cell In rg.Cells
    > If Not rg.HasFormula Then 'If not formula
    > txt = cell.Text
    > pos = InStr(txt, searchFor)
    > If pos > 0 Then 'Set Color
    > cell.Characters(pos, lenSearch).Font.Color = vbRed
    > End If
    > End If
    > Next
    >
    > End Sub
    > '-----------------------------------------------------------
    > To modify the color for all instances within a cell, modify the code within
    > the:
    > If Not rg.HasFormula Then
    > to loop within the string.
    >
    > --
    > Regards,
    > Sébastien
    > <http://www.ondemandanalysis.com>
    >
    >
    > "coco" wrote:
    >
    > > Good morning all,
    > > I have in column E, from cell E1 to E300, text information all over black
    > > color.
    > > Each cell has about 50 characters.
    > > I want to search all these cells for the string “ZZZ” and if it find the
    > > string then change ZZZ color from black to red. Only ZZZ needs to be change
    > > to red and not the whole text in the cell.
    > >
    > > Thanks
    > >
    > > Coco
    > >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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