Send a suggestion!

We're building a brand new version of the site, and we'd love to hear your ideas

Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 210,488 times

Contents

Related Categories

VBA in Excel - Text Formatting

Text Formatting

In Excel, there are 2 types of formatting. One that applies to the text in a cell, and one that applies to the cell itself. To apply formatting to the text, you use the Font object. The Font object allows you to change font face, size, bold, italic etc. For example, the following code makes the selected cell use the Tahoma font:

ActiveCell.Font.Name = "Tahoma"

The other main properties that you can change are listed below:

Property Name
Bold
Color
ColorIndex
Creator
Italic
Name
Size
Strikethrough
Subscript
Superscript
Underline

For the Name and Size properties, you simply specify a font name and size. Other properties such as Italic, are true/false properties:

Range("A1").Font.Italic = True

sets A1's text to italic. The Color property allows you to specify an actual color. You can use the RGB function to form it:

ActiveCell.Font.Color = RGB(255,0,0)

sets the active cells font colour to Red (255 red, 0 green, 0 blue). Alternatively, you can use the ColorIndex property. This lets you specify an item in the workbooks palette (this can be set in the Color tab of the Excel Options dialog).

ActiveCell.Font.ColorIndex = 16

sets the font colour to the 16th item on the colour palette.

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.

Comments

  • Re: [35] VBA in Excel

    Posted by MartinMudge on 28 Aug 2007

    Hi


    What i am trying to do is use a formula to grap cells a specific distance apart, and then use autofill to copy these cells.  Currently, I am ...

  • Re: [35] VBA in Excel

    Posted by erniede on 10 Aug 2007

    This might not be the place to ask this question, but here goes...


    I'd like to put a macro in an excel worksheet that limits the time someone can use the sheet. that is, I have a "demo" of ...

  • deleting unwanted rows

    Posted by charuambekar on 08 Feb 2006


    You need to first write a code to select the entire range, then


    Selection.SpecialCells(xlCellTypeBlanks).Select
    Selection.EntireRow.Delete



    Regards,

    Charu

  • .Borders

    Posted by djlysuc on 26 Nov 2005

    I am trying to use VB in excel 2003 to check if a cell has a border. I tried the following but it does not work. Can anyone explain how I should be doing this?

    [code]
    ActiveCell.Borders(xlEdgeLeft...

  • Try something different

    Posted by richardbarnwell on 14 Nov 2005

    Why dont you try using a For loop instead. Something like:

    x = o

    For x to 100

    // What ever you want to do

    Next x

    Makes it very easy.