0

I found this similar question on here (excel vba: make part of string bold), but I'd like to know how to tweak it to where the only the last line of every cell in a given column is bolded. Is this possible?

Short summary: I have a file with 2 columns where updates are stored with a corresponding date of the update. Here's an example, where all of this is typed in one cell:

12/15 - A meeting was held on 11/21 to discuss alternative solutions
12/22 - The field is going to be created at the account level
12/29 - The field is built in TEST environment, ready for operations testing
01/05 - Functionality confirmed; ready to move into PROD

In this example, I need the last update line, "01/05 - Functionality confirmed; ready to move into PROD" to be bolded.

Any help is greatly appreciated.

EDIT: Is there a way to update this so that it only bolds the cell in column E of that row if column L is not blank (meaning there was no updated note entered)? Otherwise, it moves on to the next row. I have the following code, but I'm constantly getting a data type mismatch error 13. Also, I'm probably missing some code as well.

Sub BoldLastLine1()
Dim p As Long
Dim r As Range

For Each r In ActiveSheet.Range("A3:L100")
    If Len(Trim(ActiveSheet.Cells(r, 12).Value)) <> 0 Then

        p = InStrRev(r.Value, vbLf)
        If p > 0 Then
            With r.Characters(p + 1, Len(r.Value) - p).Font
                .Bold = True
                .Size = 16
            End With
        End If
    End If
Next

MsgBox ("Updates Completed.")

End Sub
Jongware
  • 22,200
  • 8
  • 54
  • 100
Earl J
  • 5
  • 4
  • 1
    Is there any way to get the data in separate rows? Multi-line cells are notoriously tricky when trying to manipulate. If you do need VBA, what have you tried? You can put the cell's text in a variable, loop through that to find the last instance of `-` and work from there? – BruceWayne Jan 19 '18 at 22:24

1 Answers1

2

You can locate the last vbLf in the cell, and bold everything after that:

Sub BoldLastLine()
    Dim p As Long
    Dim r As Range
    For Each r In ActiveSheet.Range("A1:B10")
        p = InStrRev(r.Value, vbLf)
        If p > 0 Then
            r.Characters(p + 1, Len(r.Value) - p).Font.Bold = True
        End If
    Next
End Sub
YowE3K
  • 23,852
  • 7
  • 26
  • 40
  • Thanks mate, this worked like a freakin' charm! Sorry for the late reply, but I had to shift my focus to other projects before I was able to test this. – Earl J Jan 26 '18 at 19:32
  • Is there a way to update this so that it only bolds the cell in column E of that row if column L is not blank (meaning there was no updated note entered)? Otherwise, it moves on to the next row. I have the following code, but I'm constantly getting a data type mismatch error 13. Also, I'm probably missing some code as well: – Earl J Feb 15 '18 at 21:32