bold part of text

erock24

Well-known Member
Joined
Oct 26, 2006
Messages
1,161
I would like to use a macro to bold the word "Actual" in cell named "VMDate". How can I do this. The cell also contains other text that I wish to leave alone.

Thank you.
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

Colin Legg

MrExcel MVP
Joined
Feb 28, 2008
Messages
3,497
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi,

See how you get on with this:
Code:
Sub Example()
     Const sTOFIND As String = "actual"
     
     Dim lFirstChar As Long
     
     With Range("VMDate")
     
          lFirstChar = InStr(1, .Value, sTOFIND, vbTextCompare)
     
          If lFirstChar Then
            .Characters(lFirstChar, Len(sTOFIND)).Font.Bold = True
          End If
          
     End With
     
End Sub

Hope that helps...
 
Upvote 0

erock24

Well-known Member
Joined
Oct 26, 2006
Messages
1,161
Well that code worked, but since I have code that enters the text into that cell, this code only works the 1st time I run the macro. But using the recorder and editing the output I came up with this, which works fine. Thank you.

Code:
With Range("VMDate").Characters(Start:=1, Length:=6).Font
        .Bold = True
    End With
    With Range("VMDate").Characters(Start:=7, Length:=13).Font
        .Bold = False
    End With
 
Upvote 0

Forum statistics

Threads
1,191,166
Messages
5,985,050
Members
439,935
Latest member
Monty238

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
Top