Solved How to make bold fonts in a concatenated text in Excel

March 20, 2016 at 21:35:55
Specs: Windows 10
Eg In excel, I have text in A2, A3, A4, A5, A6,A7,A8. & A1 is result of concatenation from A2:A8. I would like to bold the fonts i A3, A5, A8 suing vba

See More: How to make bold fonts in a concatenated text in Excel

Report •

March 21, 2016 at 05:36:58
✔ Best Answer
I am assuming that you mean you want to bold the portion of the text in A1 that came from A3, A5 and A8.

If that is correct, you cannot do it directly in A1 because you cannot bold text that is the result of a formula. The cell that contains the formula does not contain the actual text, so there is nothing to bold.

What you can do is put your formula in another cell and then have the macro copy the result of the formula into A1. Now that A1 really does contain text, you can bold specific characters.

In this example, I chose B1 to contain the formula. You can chose any cell you want, and even hide it if you don't want to see the extraneous "text".

Sub BoldSomeText()
'Copy Text From B1 to A1
  Range("A1") = Range("B1").Value
'Loop through A3, A5 and A8
    For Each txtStr In Range("A3,A5,A8")
'Determine Start Position of text within A1
      startChar = InStr(1, Range("A1"), txtStr)
'Determine Length of text
      lenBold = Len(txtStr)
'Bold specific characters
         Range("A1").Characters(startChar, lenBold).Font.Bold = True
End Sub

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.

message edited by DerbyDad03

Report •
Related Solutions

Ask Question