I have the following:
s = 1
f = 1
For i = 1 To UBound(Split(Range("B17").Value, "<b>"))
s = InStr(f, Range("B17").Value, ("<b>"))
f = InStr(s, Range("B17").Value, ("</b>"))
Range("B17").Characters(s, f - s + 1).Font.FontStyle = "Bold"
Next i
This works to loop a cell and make all text between tags bolded. However, this also still leaves behind the tags in the cell.
I need a way to bold between AND remove the tags from a specific cell. I tried to add:
Range("B17").Value = Replace(Range("B17").Value, "<b>", "")
Range("B17").Value = Replace(Range("B17").Value, "</b>", "")
BUT, this not only removed the tags, it also removed the bold font.
Is it possible to do this?
This code first notes the position of the tags before removing them. Then, in a separate loop, it applies bold font to the noted text positions.
I thought it's a bit slow. Therefore I wanted to pause screen updating (
Application.ScreenUpdating = False) while it runs but refrained. The reason is that the procedure just formats a single cell. You would probably call it from another procedure that loops through all your cells in a column, feeding each one to the above proc in turn. Use code likeSetCharsBold Range("F1"). The screen control should be done in that procedure, delaying the update until its loop has run.I forgot to remove
Cell.Offset(18)from the code and decided to leave it there on second thought. I didn't want the code to over-write the original texts. Perhaps you have a similar need. Please adjust that line to suit.