Having partial text in a cell change to bold.

Copper Contributor

I'm trying to have Excel bold the text after "MM " in a cell. I would like to have it do this for the entire range. Right now I'm doing it manually. Here is an image of my worksheet.

ScottF1870_0-1723062014966.png

Any help would be appreciated.

Thank you.

Scott

 

4 Replies

@ScottF1870 

The following will on;y work in the desktop version of Excel for Windows or Mac.

Press Alt+F11 to activate the Visual Basic Editor.

Select Insert > Module.

Copy the following code into the new module:

Sub BoldAfterMM()
    Dim c As Range
    Dim p As Long
    Application.ScreenUpdating = False
    For Each c In Range(Cell1:=Range("A2"), Cell2:=Range("A2").End(xlDown))
        p = InStr(c.Value, "MM")
        If p > 0 Then
            c.Characters(Start:=p + 2, Length:=1000).Font.Bold = True
        End If
    Next c
    Application.ScreenUpdating = True
End Sub

With the insertion point anywhere in the code, press F5 to execute it.

Switch back to Excel.

If you want to be able to run the macro again later on, save the workbook as a macro-enabled workbook (*.xlsm) and make sure that you allow macros when you open it.

@HansVogelaar Thank you for the amazingly quick response. Unfortunately, we use Microsoft 365. I tried it anyway but it didn't work.  Again, though....thank you

Scott

@ScottF1870 If you have any version of Microsoft 365 except for Microsoft 365 Basic, you can use the desktop version of Excel on Mac and Windows. If you do not have that yet, you can install the local apps by logging in to https://www.office.com with your Microsoft 365 account and clicking the Install link.

The macro should work - I tested it using Excel in Microsoft 365 for Windows.

@ScottF1870 

online sql:

select regreplace('(?<=MM).*','<b>\0</b>',f01),* from Sheet2;

https://e.anyoupin.cn/EData/?s=1321

Screenshot_2024-08-08-08-49-30-437_com.microsoft.office.excel.jpg