I'm trying to write a VBA script that goes through a column of cells and one, underlines text between html <u></u>
tags and two, removes those tags from the text afterwards. Cells may have multiple tags inside of them, other text next two them, or no tags at all.
So far I've been able to get the script to underline between tags but when I try to remove them nothing really works (sometimes nothing is changed, sometimes the tag is underlined, etc.). I'm omitting input/output examples for brevity and in the hopes that there are glaringly obvious issues with my code but they are available on request.
Trying to solve this problem using VBA initially stems from an inability for me to do this in Python since the object model only goes as low as cells, not the content of the cell. Any solutions using Python to do this would also be appreciated!
Thank you so much for the help! Let me know if there's anything else I can do to help you all!
Sub PleaseUnderline()
'Holds the content between the tags
Dim s As String
'Holds the row number of the active cell
Dim a As Integer
'Holds the location of the beginning of the open tag
Dim b As Integer
'Holds the location of the beginning of the close tag
Dim e As Integer
Dim holder As String
'Select the last cell in column A and make it the active cell
Range("A" & ActiveCell.SpecialCells(xlLastCell).Row).Select
For a = ActiveCell.Row To 1 Step -1
Range("A" & a).Select
holder = Range("A" & a).Value
s = ""
b = 1
e = 1
Do
b = InStr(b, ActiveCell, "<u>")
If b = 0 Then Exit Do
e = b + 1
e = InStr(e, ActiveCell, "</u>")
If e = 0 Then
Exit Do
Else
s = Mid(ActiveCell, b + 3, e - b - 3)
End If
holder = Replace(holder, "<u>", "", 1, 1)
holder = Replace(holder, "</u>", "", 1, 1)
Worksheets("Sheet").Range("A" & a).Value = holder
ActiveCell.Characters(b, Len(s)).Font.Underline = True
b = e + 1
Loop
Next a
End Sub