If you make a selection and turn the macro recorder on and there will be 38 lines of code produced to get borders inside outside horizontal and vertical. Creating a macro to apply excel vba borders with different style making them available as an add in to the excel ribbon makes the job easier whenever we want to apply vba borders.
Https Encrypted Tbn0 Gstatic Com Images Q Tbn 3aand9gct Ugwlef Gezhbs0ucmvgjyj2xzsa Ckszkdhfed Wmii 5xmb Usqp Cau
Alt h will enable the home menu b will enable the borders.
How to add borders in excel vba.
Expression a variable that represents a range object.
For accessing borders the shortcut way first select the data which we want to frame with borders and then press alt h b simultaneously to enable the border menu in excel.
In this article i will explain how you can make basic borders using vba for excel.
On the home tab in the font group do one of the following.
When you add interior colour in excel the borders tend to disappear so adding them back gives the look as follows.
Select the cells you want to format.
Activate the worksheet first in order to use its properties by the following.
Click the down arrow beside the borders button in the font group on the home tab.
Declare a sub function which means naming our macro.
Vba borders step 1.
That is a complete boarder around every cell.
Insert a new module from the insert tab provided.
This example sets the color of the bottom border of cell b2 on sheet1 to a thin red border.
If you want to use this code in your vba tool then follow below steps.
Each range of cells can accept up to 8 different types of borders.
Every cell in a worksheet has borders and background colors.
Open the module in which you want to add this code.
Apply or remove cell borders on a worksheet apply a predefined cell border on a worksheet select the cell or range of cells that you want to add a border to change the border style on or remove a border from.
Paste this code just after the code where you want to add the borders in the sheet.
Left edge xledgeleft top edge xledgetop bottom edge xledgebottom right edge xledgeright inside vertical xlinsidevertical inside horizontal xlinsidehorizontal.
Rangeborders property excel returns a borders collection that represents the borders of a style or a range of cells including a range defined as part of a conditional format.
A drop down menu appears with all the border options you can apply to the cell selection.
Use the borders button on the home tab to choose borders for the selected cells.
Go to developers tab open visual basic and we will see a vb editor.
Open the excel file in which you want to copy this code.
No comments:
Post a Comment