Excel 2007 VBA tutorial-VBA code to set text font


VBA code to set text font

In this example, you will learn VBA code to set styles of font of text containing in cells of Excel worksheet. The VBA code will change the text of cells from A1 to A5 to font styles: bold, italic, red color, size 20, and name Arial.

To run this example VBA code, you will need a Form and a Button.



VBA for Excel: VBA code example of using VBA code to set font style of text in cells
VBA code to set font styles of text in cells:

 Private Sub CommandButton1_Click()
  Dim c As Variant
  For Each c In Range("A1:A5").Cells
    With c.Font
      .Bold = True
      .Italic = True
      .Color = RGB(255, 0, 0)
      .Size = 20
   .Name = "Arial"
   End With
  Next

 End Sub


Comments





This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.