How to Highlight or Underline the Last Word in an Excel Cell
Working with data in Excel can be simplified by customizing cell formatting to suit your needs. One common task is to highlight or underline the last word in a cell. This can be achieved using VBA (Visual Basic for Applications) scripts or by a combination of manual steps. Below, we explore both methods.
Using VBA to Highlight the Last Word
If you're comfortable with VBA, you can create a macro to automatically highlight the last word in every cell of a selected range.
' Subroutine to bold the last word in a selection Sub BoldLastWord Dim rng As Range Dim str As String Dim x As Integer Dim LastWord As String Set rng Selection For i 1 To str rng(i).Value LastWord Right(str, Len(str) - InStrRev(str, " ")) x InStr(str, LastWord) With rng(i).Characters(Start:x, Length:Len(LastWord)).Font .Bold True End With Next End Sub ' Subroutine to strike through the last word in a selection Sub STLastWord Dim rng As Range Dim str As String Dim x As Integer Dim LastWord As String Set rng Selection For i 1 To str rng(i).Value LastWord Right(str, Len(str) - InStrRev(str, " ")) x InStr(str, LastWord) With rng(i).Characters(Start:x, Length:Len(LastWord)).Font .Strikethrough True End With Next End Sub
This VBA code defines two subroutines: BoldLastWord and STLastWord. The first routine bolds the last word in each selected cell, and the second strikes through it. You can assign these macros to buttons or use them in custom applications to enhance your Excel workflow.
Manual Steps for Highlighting or Underlining the Last Word
For a more manual approach, you can still highlight or underline the last word in a cell. Here's how:
Place your cursor on the cell you want to edit. Press F2 to enter edit mode. Highlight the last word using the Shift key and the Left Arrow key. Press Ctrl U to underline the selected text. To change the font color, click on the color icon in the Ribbon.An alternative method is to:
Select the cell with the text. Move up to the Formula bar and double-click on the last word. Choose Underline from the formatting options.Note that Excel does not have a direct feature to highlight a single word. Instead, you can change the font color of that word or make it bold to achieve a similar effect.
Conclusion
Whether you're working with VBA scripts or manual methods, you can easily highlight or underline the last word in an Excel cell. These techniques are particularly useful for improving data readability, especially in long or complex sheets. Experiment with these methods to find the one that best suits your needs.