Hi, I need some help to format a spreadsheet. I need a macro that will bold specific text and insert a newline before said text. The bold works, but I don't know the best way to insert the linebreak. I tired with cell.Replace but that's acting weird. Maybe someone has a better solution.
When I uncomment line 10 it kinda works but acts oddly when I test multiple cells. I'm sure there is a better way to accomplish this but I don't know what that would be.
Also, some cells are empty, some cells have both [TITLES] and still others have one or the other.
Thanks for your help!
VBA Code:
Sub Find_and_Bold()
Dim rCell As Range, sToFind As String, iSeek As Long
Dim Text(1 To 4) As String
Dim i As Integer
Text(1) = "[CUSTOMIZED APPROACH OBJECTIVE]:"
Text(2) = "[APPLICABILITY NOTES]:"
For Each rCell In Range("D1:D100")
'rCell.Replace What:="[", Replacement:=vbLf & "["
For i = LBound(Text) To UBound(Text)
sToFind = Text(i)
iSeek = InStr(1, rCell.Value, sToFind)
Do While iSeek > 0
rCell.Characters(iSeek, Len(sToFind)).Font.Bold = True
iSeek = InStr(iSeek + 1, rCell.Value, sToFind)
Loop
Next i
Next rCell
End Sub
When I uncomment line 10 it kinda works but acts oddly when I test multiple cells. I'm sure there is a better way to accomplish this but I don't know what that would be.
The excel sheet looks like this before formatting. | I would like it to look like this after I run the macro. |
---|---|
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. [CUSTOMIZED APPROACH OBJECTIVE]: Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.[APPLICABILITY NOTES]: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. [CUSTOMIZED APPROACH OBJECTIVE]: Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. [APPLICABILITY NOTES]: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. |
Also, some cells are empty, some cells have both [TITLES] and still others have one or the other.
Thanks for your help!