Make part of string bold, before character ":"

mdd16

Board Regular
Joined
Jan 11, 2011
Messages
84
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have a range with several cells that have text divided in two parts by a ":" character. I want to make the words before character ":" to be converted to Bold Font.
Can someone help me with the required via code please.

Existing TextWanted
Heading Text example 1 : Body Text 1Heading Text example 1 : Body Text 1
Heading Text something 2 : Body Text 2Heading Text something 2 : Body Text 2
Heading Text something else 3 : Body Text 3Heading Text something else 3 : Body Text 3
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Change the column the data is in to suit.

VBA Code:
Sub Boldy()
    Dim cell As Range, i As Long
    Application.ScreenUpdating = False
    For Each cell In Range("A2", Range("A" & Rows.Count).End(xlUp))
        i = InStr(cell.Value, ":")
        If i Then cell.Characters(1, i).Font.Bold = True
    Next cell
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Change the column the data is in to suit.

VBA Code:
Sub Boldy()
    Dim cell As Range, i As Long
    Application.ScreenUpdating = False
    For Each cell In Range("A2", Range("A" & Rows.Count).End(xlUp))
        i = InStr(cell.Value, ":")
        If i Then cell.Characters(1, i).Font.Bold = True
    Next cell
    Application.ScreenUpdating = True
End Sub
Many thanks for your reply.

I am getting error. "Method Range of Object ' _Global' failed

The ranges that need this code are named like SpecL1_LM .. SpecL2_LM... to SpecL17_LM. Each range is merged cells from Col C to Col P, one row each

The ranges referred above are merged cells starting from C30 to P46. Ideally I wound want to apply cell names as I need to apply this code to many sheets with same cell names defined for each sheet.

Code modified to suit my wb is as follows

Sub MakeBold_BefChr()

'For Each cell In Range(SpecL17_360, Range(SpecL17_360 & Rows.Count).End(xlUp))
For Each cell In Range("A30", Range(A & Rows.Count).End(xlUp))
i = InStr(cell.Value, ":")
If i Then cell.Characters(1, i).Font.Bold = True
Next cell
End Sub

Thanks a ton in advance.
Mohan
 

Attachments

  • Error for Boldy.jpg
    Error for Boldy.jpg
    36.2 KB · Views: 9
Upvote 0
Hello and thanks for help.

The code suggested was not working. But then taking guidance from it I used following

For Each cell In Sheets("360 LM Prnt").Range("C30:P46")
i = InStr(cell.Value, ":")
If i Then cell.Characters(1, i).Font.Bold = True
Next cell

The code worked wonderfully once. But after a couple of times it stops working.. Strange..
After 2-3 time usage on the same range, it starts to give all characters as bold. Why should that be happening ?

Any help will be much appreciated.
 
Upvote 0

Forum statistics

Threads
1,215,065
Messages
6,122,945
Members
449,095
Latest member
nmaske

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