Solved How To Bold Variable Text In A Concatenated String In Excel

November 11, 2016 at 14:32:06
Specs: MS Windows 7 Enterprise, Intel(R) Core(TM) i7-2860QM CPU @2.5GHz, 2501Mhz
I have applied the code from the question posted March 20,2016 (, but the code doesn't determine the length of the text to bold, the code bolds all the text from the startChar to the end of the string. What do I need to add to bold ONLY the concatenated value from one of the cells in the string?

This is the code I am using:

Sub BoldSomeText2()

'Copy Text From L21 to A26

Range("DeclaredISOYield") = Range("L21").Value

'Loop through B9,L23,and L24

For Each txtStr In Range("B9,L23,L24")

'Determine Start Position of text within L21

startChar = InStr(1, Range("StatedYield"), txtStr)

'Determine Length of text

lenBold = Len(txtStr)

'Bold specific characters

Range("DeclaredISOYield").Characters(31, txtStr).Font.Bold = True

End Sub

My intent is to create a report in which the numeric result of a formula that appears in a cell (B9, in this case) concatenates with content from other cells, but only the variable numeric value from B9 is in bold face.

Thank you for your help!

See More: How To Bold Variable Text In A Concatenated String In Excel

Reply ↓  Report •

November 25, 2016 at 05:33:13
✔ Best Answer
Do you want the VBA code to concatenate the strings for you or are you using a formula to do this?

how are the cells concatenated?

Cell 1 Cell 2
123 Mouse

does the string get concatenated like 123Mouse or Mouse123?

Look at this code for example

Sub BoldNumbers()

    itext = Range("A1")
    For i = 1 To Len(itext)
        If Not IsNumeric(Mid(itext, i, 1)) Then
            Exit For
        End If
    Next i
    Range("A1").Characters(1, i - 1).Font.Bold = True
End Sub

if in range A1 you have 123Mouse the code will bold the numbers so the result will be


So the concept is possible just need to know a few details as per above.

message edited by AlwaysWillingToLearn

Reply ↓  Report •

December 5, 2016 at 05:37:33
i know you have marked this as solved, but would be good to know if the code actually worked for what you wanted it for?

Reply ↓  Report •

Related Solutions

Ask Question