• macro to bold just first word of a cell

    Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » macro to bold just first word of a cell

    Author
    Topic
    #475937

    I need a macro that will bold just the first word of a cell in which there is existing text. (Excel 2007). I tried recording a macro, but every time I use it, it just changes cell to whatever the first cell was.

    Suggestions.?
    Thanks

    Viewing 1 reply thread
    Author
    Replies
    • #1274976

      This should do the trick.

      Code:
      Option Explicit
      
      Sub BoldFirstWord()
      ‘
          Dim lEnd  As Long
          
          If WorksheetFunction.IsText(ActiveCell.Value) Then
            With ActiveCell
                lEnd = InStr(1, .Text, ” “, 1) – 1
                .Characters(Start:=1, Length:=lEnd).Font.FontStyle _
                  = “Bold”
            End With
          End If
          
      End Sub

      :cheers:

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1274981

      If you modify Retired Geek’s code you can have it bold all the first words in a selected range of cells:

      Steve

      Code:
      Option Explicit
      Sub BoldFirstWordInSelection()
        Dim lEnd  As Long
        Dim rCell As Range
        For Each rCell In Selection
          If WorksheetFunction.IsText(rCell.Value) Then
            With rCell
              lEnd = InStr(1, .Text, " ", 1) - 1
              .Characters(Start:=1, Length:=lEnd).Font.FontStyle _
                = "Bold"
            End With
          End If
        Next
      End Sub
    Viewing 1 reply thread
    Reply To: macro to bold just first word of a cell

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: