Results 1 to 4 of 4
  1. #1
    4 Star Lounger
    Join Date
    May 2002
    Posts
    410
    Thanks
    1
    Thanked 0 Times in 0 Posts

    macro to bold just first word of a cell

    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

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,433
    Thanks
    371
    Thanked 1,456 Times in 1,325 Posts
    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
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. #3
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts
    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

  4. #4
    4 Star Lounger
    Join Date
    May 2002
    Posts
    410
    Thanks
    1
    Thanked 0 Times in 0 Posts
    works.
    thanks!!

Posting Permissions

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