Reputation: 353
I am fairly new to the VBA world. I was wondering if there is any way that you could use underline, bold and Italic in a single cell. In this example, I would like just the first and second line to be bold, with the name coming 2 hyphens after the first word, and the third line underline. Not entirely sure if this is possible. The first cell shows what I have. The second cell shows what I'm looking for.
Upvotes: 1
Views: 628
Reputation: 5902
If you want to perform this on several cells then you can use below code as a starting point. I have provided comments in the code which should assist you to understand.
Public Sub HUBSpecificStyle()
Dim rng As Range
Dim varContent, varFirstRow
'\\Loop through all cells in selection
For Each rng In Range("A2:B2") '\\ Set your range reference here
varContent = Split(rng.Value, Chr(10)) '\\ Split cell contents by newline character
With rng
'\\ First two lines of row bold
.Characters(1, Len(varContent(0) & Chr(10) & varContent(1))).Font.Bold = True
'\\Third line underline
.Characters(Len(varContent(0) & Chr(10) & varContent(1) & Chr(10)) + 1, Len(varContent(2))).Font.Underline = True
'\\ Split first line with hyphens
varFirstRow = Split(varContent(0), "-")
'\\Third part italic
.Characters(Len(varFirstRow(0) & "-" & varFirstRow(1) & "-") + 1, Len(varFirstRow(2))).Font.Italic = True
End With
Next rng
End Sub
Upvotes: 4