2021年1月26日星期二

How to Bold certain text part of a string

I have a string within a cell and I am trying to bold certain parts of that string. I have my code setup so each case is a line within that cell.

The first cell is what I am starting out with, and the one below it is what I am trying to do. Below is my code on what I have so far.

enter image description here

Sub test()                For Each cel In Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row)                                  Dim arr, line As Long, pos As Long, txt, length, dashPos                                      arr = Split(cel.Value, Chr(10)) ' Spliting cell contents by newline character                                      pos = 1                   For line = 1 To UBound(arr) + 1                                              txt = arr(line - 1)                       length = Len(txt)                                          'check which line we're on...                       Select Case line                           Case 4: 'Underline on line 4                               cel.Characters(pos, length).Font.Underline = True                           Case 5: 'Bold the team players                                                                                       Case 6: 'Underline on line 6                               cel.Characters(pos, length).Font.Underline = True                       End Select                                          pos = pos + Len(txt) + 1 'start position for next line                   Next line                        Next cel  End Sub  
https://stackoverflow.com/questions/65912765/how-to-bold-certain-text-part-of-a-string January 27, 2021 at 12:08PM

没有评论:

发表评论