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:
- Single, xlUnderlineStyleSingle
- Double, xlUnderlineStyleDouble
- Single Accounting, xlUnderlineStyleSingleAccounting
- Double Accounting, xlUnderlineStyleDoubleAccounting
Contents
Single, xlUnderlineStyleSingle:
The following line of code creates an underline for the font in cell A1:
Range("A1").Font.Underline= xlUnderlineStyleSingle
Before:
After:
Double, xlUnderlineStyleDouble:
The following line of code creates a double underline for the font in cell A1:
Range("A1").Font.Underline= xlUnderlineStyleDouble
Before:
After:
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:
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:
After:
xlUnderlineStyleNone: The following line of code removes the underline for the font in cell A1:
Range("A1").Font.Underline = xlUnderlineStyleNone
See also:
- VBA Excel Font Formatting
- Excel VBA Set Underline (Sample Code + Download)
- Excel VBA Get Underline (Sample Code + Download)
- Excel VBA, Formatting Cells and Ranges Using the Macro Recorder
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