Next, select the border style option and at the very bottom, you should see a double. The second part of the code checks which value was chosen from the drop down list in cell B2 and adjusts the border thickness of the bottom edge of the range C4:F4 accordingly: If Cells (2, 2) 'Thin' Then. Also please visit my website www.software-solutions-online. First, in the top toolbar menu, select Borders 2. If you need assistance with your code, or you are looking for a VBA programmer to hire feel free to contact me. Adds a double-line underline, the width of the cell contents. Adds a single underline, the width of the cell contents. Removes any underlining from the cell contents. In the Underline box, in the lower-left corner, you can select any of five different underline types.
Excel VBA, Formatting Cells and Ranges Using the Macro Recorder The Font tab of the Format Cells dialog box.Excel VBA Get Underline (Sample Code + Download).The If statement below checks if the user selected the Double Accounting underline style from the drop down list: The If statement below checks if the user selected the Single Accounting underline style from the drop down list: The If statement below checks if the user selected the Double underline style from the drop down list: The If statement below checks if the user selected the Single underline style from the drop down list: The If statement below checks if the user selected “None” from the drop down list: The event handler loops through the columns and makes the necessary changes: Range(Cells(2, i), Cells(2, i)).Font.Underline _ĮlseIf Cells(1, i) = "Single Accounting" ThenĮlseIf Cells(1, i) = "Double Accounting" Then Private Sub worksheet_change( ByVal target As Range) For a thin underline, which does not exactly overlap the text, copy the text below. 'executes when the user selects a new value from the drop down lists There is no obvious simple method to add a non-bold underline to bold text. The event handler executes when the user selects a new value from the drop down lists:
The program uses a Worksheet_Change event handler. The data for the drop down lists are stored in sheet 2: For more information about creating drop down lists in excel please see Excel VBA Drop Down Lists. The drop down lists are created using data validation.
In the figure below the user is selecting an underline style for cell C2 from the drop down list in cell C1:Īfter making the selection the underline style is update in the cell below: When the user makes a selection the underline style will change in row 2: The user selects an underline style from the drop down lists in row 1.
You can download the file and code related to this article here. There are 4 different underline style the user can select from:įor more information about the different underline types and their associate VBA code please see Excel VBA, Underline Font Style. In this article I’ve provided an example on how you could use VBA to set underlines for cells and ranges.