Combining strings that have bold characters

Dan Waterloo

Well-known Member
Joined
Jan 4, 2007
Messages
876
Let's say that this sentence is in A1:
Rich (BB code):
The king is dead.
If it isn't clear, the word "king" is bolded but the rest of the sentence isn't.

Further, the sentence, "Long live the king!" is in cell A2. It isn't bolded at all.

How can I combine these two sentences in cell A3 so that the first instance of "king" remains bolded? A solution using either VBA or a formula would be fine with me. (But I don't want a solution where the strings get concatenated and then the bolding gets applied afterwards in some hard-coded fashion.)
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
The only way I would think this would be possible would be to check each letter individually to see if they are bolded or not?

This could be made more dynamic, but it currently only set for A1, A2 and A3. Depending on how many cells you are concatenating it could always combine the 2 cells above the current cell, but you would need to further explain your ultimate goal of this?

Code:
Sub test()
Range("A3").ClearContents
Range("A3").Value = Range("A1").Value & " " & Range("A2").Value
For i = 1 To Len(Range("A1").Value)
    If Range("A1").Characters(i, 1).Font.Bold = True Then Range("A3").Characters(i, 1).Font.Bold = True
Next i
For j = 1 To Len(Range("A2").Value)
If Range("A2").Characters(j, 1).Font.Bold = True Then Range("A3").Characters(j + Len(Range("A1").Value) + 1, 1).Font.Bold = True
Next j
End Sub
Hope that helps.

Here are some samples of the code:

Excel Workbook
A
1The king is dead.
2Long live the king!
3The king is dead. Long live the king!
Sheet1



Excel Workbook
A
1The king is dead.
2Long live the king!
3The king is dead. Long live the king!
Sheet1
 
Upvote 0

Forum statistics

Threads
1,215,854
Messages
6,127,342
Members
449,377
Latest member
CastorPollux

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top