Results 1 to 2 of 2
  1. #1
    3 Star Lounger
    Join Date
    Mar 2004
    Location
    North Carolina, USA
    Posts
    268
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Bold Certain Text (2002)

    I want to bold and change color of "pro hac vice" that occurs on a spreadsheet within other text (same cell) on a spreadsheet. I only want to do that to these words and leave the other words as is.

    How do I do this?

    Mitch

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Bold Certain Text (2002)

    Manually:
    - Select a cell containing the text "pro hac vice"
    - Click in the formula bar.
    - Select the text "pro hac vice".
    - Apply the font changes you want.
    - Press Enter when done.

    Automatically:
    - Put the following code in a module:

    Sub FormatText()
    Dim strText As String
    Dim rngCell As Range
    If Selection Is Nothing Then Exit Sub
    On Error GoTo ErrorHandler
    For Each rngCell In Selection.SpecialCells(xlCellTypeConstants).Cells
    FormatTextInCell rngCell, "pro hac vice"
    Next rngCell
    Exit Sub
    ErrorHandler:
    MsgBox "Something went wrong.", vbExclamation, "Sorry"
    End Sub

    Sub FormatTextInCell(rngCell As Range, strText As String)
    Dim strVal As String
    Dim intPos As Integer
    Dim intLen As Integer
    intLen = Len(strText)
    strVal = rngCell.Value
    intPos = InStr(strVal, strText)
    Do While intPos > 0
    With rngCell.Characters(intPos, intLen).Font
    .Bold = True
    .ColorIndex = 3
    End With
    intPos = InStr(intPos + intLen, strVal, strText)
    Loop
    End Sub

    - Select a range.
    - Run the macro FormatText.

Posting Permissions

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