Applying different formatting to text in formula

Zaigham

Board Regular
Joined
Dec 22, 2010
Messages
159
Office Version
  1. 2021
Platform
  1. Windows
  2. Mobile
Excel gives opportunity to apply different formatting to text within a single text. Here is a sample to explain my question. In simple text string XL offer different formatting to various parts of sentence but in a concatenated cell whole string could be formatted e.g., bold, underline or a single colour.
Is there any way to apply different formatting to concatenated text in a formula?
This is a sample of applying different formatting to text.

Excel Workbook
A
1This is a sample of applying different formatting to text.
2*
3This is a
4sample of
5applying different
6formatting to text.
7*
8This is a sample of applying differentformatting to text.
Sheet1
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hi

No. All the characters resulting from a formula will have the same format.

If you need different formats in the text of the cell, the cell must have a constant value, not a formula. Either you enter it manually or use vba to build the result of the concatenation, write the result in the cell as a constant and format it.
 
Upvote 0
Hi PGC

Can you guide me to a VBA. However, thanks for information.

Regards
Zaigham
 
Upvote 0
Code:
[COLOR="Blue"]Sub[/COLOR] FormatChars()
    [COLOR="Blue"]With[/COLOR] Range("B1")
        .Value = Range("A3") & Range("A4") & Range("A5") & Range("A6")
        [COLOR="Blue"]With[/COLOR] .Characters(1, 9) [COLOR="green"]'First 9 characters...[/COLOR]
            .Font.Bold = [COLOR="Blue"]True[/COLOR]
            .Font.ColorIndex = 3
        [COLOR="Blue"]End[/COLOR] [COLOR="Blue"]With[/COLOR]
        [COLOR="Blue"]With[/COLOR] .Characters(10, 10) [COLOR="Green"]'Next 10 characters...[/COLOR]
            .Font.ColorIndex = 5
        [COLOR="Blue"]End[/COLOR] [COLOR="Blue"]With[/COLOR]
        [COLOR="Blue"]With[/COLOR] .Characters(20) [COLOR="Green"]'Remained characters...[/COLOR]
            .Font.ColorIndex = 7
        [COLOR="Blue"]End[/COLOR] [COLOR="Blue"]With[/COLOR]
    [COLOR="Blue"]End[/COLOR] [COLOR="Blue"]With[/COLOR]
[COLOR="Blue"]End[/COLOR] [COLOR="Blue"]Sub[/COLOR]
 
Last edited:
Upvote 0
Dear Sektor

Thanks for providing VBA. I will try to use this VBA according to my needs. In case of failure I will refer you again.

Regards
Zaigham
 
Upvote 0

Forum statistics

Threads
1,224,596
Messages
6,179,807
Members
452,944
Latest member
2558216095

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