Bold part of a text with a formula

Foxy Lady

New Member
Joined
Feb 25, 2009
Messages
41
Hi there,

I am struggling to get the code for bolding part of a text with a formula.

My sentence is

="That the monkey ate all the appels dated "&TEXT(InRisk,"dd mmmm yyyy")

The date should be in bold

Please help
 
I am pretty certain that once you apply a formula to a cell, you can only format the whole cell and not a portion of it. If the cell were pure text, then you can format individual words and sections.

For instance, a cell can look like this:

The quick brown fox.

only if it is entered as straight text, not using the = sign and quotes.
 
Upvote 0
You would need to create a VBA solution that will make the cell text and format it on sheet recalculate. The formula would cease being a formula, and would start being a macro that puts text in cells.
 
Upvote 0
Well, you can place the date portion only in another cell and can format the cell to display the bold text. I don’t think there is really a way to display a part of text in bold face in a cell because once you apply formatting to a cell it will be applied to the whole content of that cell.
 
Upvote 0
Hi there,

I am struggling to get the code for bolding part of a text with a formula.

My sentence is

="That the monkey ate all the appels dated "&TEXT(InRisk,"dd mmmm yyyy")

The date should be in bold

Please help
Select the range and try
Code:
Sub test()
Dim r As Range, i As Long, m As Object
With CreateObject("VBScript.RegExp")
    For i = 1 To 12
        myPtn = myPtn & "|" & MonthName(i, False)
    Next
    .Pattern = "\d{2} (" & Mid(myPtn,2) & ") \d{4}"
    .Global = True
    For Each r In Selection
        If .test(r.Text) Then
            r.Value = r.Text : r.Font.Bold = False
            For Each m In .execute(r.Text)
                r.Characters(m.firstindex + 1, m.length).font.bold = Ture
            Next
        End If
    Next
End With
End Sub
 
Upvote 0
Hi there, I have tried the above but it doesn't seem to work. Isn't there any other way that i can use vba code instead of the formula in the formula bar.

I have download the example and are trying to use it to make one of my forms for work easier and more electronic. Now we need to write the details in manually.
Should I attach the file
 
Upvote 0
How is it not working ?
Any error ?
Did you select the range before you run the code ?
try change
Rich (BB code):
        myPtn = myPtn & "|" & MonthName(i, False)
to
Rich (BB code):
        myPtn = myPtn & "|" & Format(DateValue(i & "/1/" & Year(Date)),"mmmm")
 
Upvote 0
Hi there,

I am struggling to get the code for bolding part of a text with a formula.

My sentence is

="That the monkey ate all the appels dated "&TEXT(InRisk,"dd mmmm yyyy")

The date should be in bold

Please help


Greetings,

I may be missing something, but as the text string appears to be a constant, you are just looking to update the date according to your named range of RiskDate (which I presume is a one cell range on the same sheet), and want to bold the date...

Let's try using a worksheet event. Now in my example, since I don't know where RiskEvent is, or where you're putting the info, this will use cell A1 to put in the info in, and it will get the date from cell B1. Adjust to suite.

Right - Click on the sheet tab, choose View Code, Paste:

Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

    If Not Application.Intersect(Target, Range("B1")) Is Nothing _
    And Not Range("B1").Value = vbNullString _
    And Not Target.Count > 1 Then
    
    
        With Range("A1")
            .Value = "That the monkey ate all the appels dated " & Format(Range("B1"), "dd mmmm yyyy")
            .Characters(42).Font.Bold = True
        End With
    End If
    
End Sub


Does that help?

Mark
 
Last edited:
Upvote 0

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