I have a csv file which includes the html tags < b > and <\ b > to signify bold text. (I.e several words between these tags, in a longer block of text within the cell, should be bold). Is there a way using vba code in excel to strip the tags, and make the text between the tags bold?
Note - There are sometime multiple sets of tags within a given cell.Answer1:
This should do what you want:
Sub BoldTags() Dim X As Long, BoldOn As Boolean BoldOn = False 'Default from start of cell is not to bold For X = 1 To Len(ActiveCell.Text) If UCase(Mid(ActiveCell.Text, X, 3)) = "<B>" Then BoldOn = True ActiveCell.Characters(X, 3).Delete End If If UCase(Mid(ActiveCell.Text, X, 4)) = "</B>" Then BoldOn = False ActiveCell.Characters(X, 4).Delete End If ActiveCell.Characters(X, 1).Font.Bold = BoldOn Next End Sub
Currently set to run on the activecell, you can just plop it in a loop to do a whole column. You can easily adapt this code for other HTML tags for Cell formatting (ie italic etc)
This was in the cell I tested on (minus the space after <): Sample < b>Te< /b>st of < B>bolding< /B> end
The result was: Sample <b>Te</b>st of <b>bolding</b> end
Hope that helps