Excel VBA, Underline Font Style

This article explains the different types of underlines possible to apply to cells and ranges. It also provides the associated VBA code for adding the underline.

For examples using these codes please see:

Jump To:


Contents

Single, xlUnderlineStyleSingle:

The following line of code creates an underline for the font in cell A1:

Range("A1").Font.Underline= xlUnderlineStyleSingle

Before:

Excel, VBA, Normal Font

After:

Excel, VBA, Underline Font


Double, xlUnderlineStyleDouble:

The following line of code creates a double underline for the font in cell A1:

Range("A1").Font.Underline= xlUnderlineStyleDouble

Before:

Excel, VBA, Normal Font

After:

Excel, VBA, Underline Font Double


Single Accounting, xlUnderlineStyleSingleAccounting:

The following line of code creates a single accounting underline. Note that this underline covers the entire cell regardless of the text inside the cell:

Range("A1").Font.Underline= xlUnderlineStyleSingleAccounting

Before:

Excel, VBA, Normal Font
After:

Excel, VBA, Underline Single Accounting


Double Accounting, xlUnderlineStyleDoubleAccounting:

The following line of code creates a double accounting underline. Note that this underline covers the entire cell regardless of the text inside the cell:

Range("A1").Font.Underline= xlUnderlineStyleDoubleAccounting

Before:

Excel, VBA, Normal Font

After:

Excel, VBA, Underline Double Accounting

xlUnderlineStyleNone: The following line of code removes the underline for the font in cell A1:

Range("A1").Font.Underline = xlUnderlineStyleNone

See also:

If you need assistance with your code, or you are looking for a VBA programmer to hire feel free to contact me. Also please visit my website  www.software-solutions-online.com

Leave a Reply

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