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

Time:03-23

The situation :

I got a cell that contains this formula :

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

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.

CodePudding user response:

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

  • Related