Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I bold a part of a text that contains a formula?

The situation :

I got a cell that contains this formula :

="Made in Paris, the "&TEXTE(AUJOURDHUI();"jj/mm/aaaa")&"."

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

And it comes out as :

Made in Paris, the 23/03/2022.

My approach of the problem :

Worksheets("AAA").Range("C8").Characters(30, 66).Font.Bold = True

It doesn’t work because there is a formula, I think…

Now I need you all help to make it look like :

Made in Paris, 23/03/2022.

Thanks in advance.

>Solution :

You cannot do it with the formula in the cell.
But you can put the formula in a VBA macro.
And you could trigger the macro to run on certain events, or trigger it manually.

For example:

Option Explicit
Sub boldDate()
    Dim r As Range
    Const sText As String = "Made in Paris, "
    Dim sResult As String
    Dim Start As Long, Length As Long
Start = Len(sText) + 1
Length = 10

Set r = Selection 'Or specify the cell where you want this written.

With r
    .Value = sText & Format(Date, "dd/mm/yyyy")
    .Characters(Start, Length).Font.Bold = True
End With

End Sub

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading