Excel VBA Code to change Font of the First 5 letters in a single cell

Last modified date

Excel VBA code to change font
Before
Excel VBA code to change font
After

Suppose we have text “Commerce and Excel hub” in Cell B3 like the example shown.

Now using VBA we want to change the font to bold only for word “Commerce” like the example shown.

You can use below code for the same. 

Sub Test()
Range("B3").Characters(Start:=1, Length:=8).Font.FontStyle = "Bold"
End Sub

Explanation of Above Code line.

  • Range(“B3”) is cell address
  • Characters are letters in the cells
  • The start is the position of the first letter for which we want to change the font
  • Length is the position of the last letter for which we want to change the font
  • .font .fontstyle=”bold” will help to change the font as per request (In this case we have selected bold)
  • Test() is the name of the macro. Sub & End sub is to start and end the VBA code.

Leave a Reply

Your email address will not be published. Required fields are marked *

Post comment