Excel VBA, Border, and Style
Introduction
As we have mentioned already, a cell appears and behaves like a rectangular box. As such, it has borders and a background. Microsoft Excel provides a default appearance for a cell with regards to its background. For example, it surrounds the cell with a gray border and a white background. You can keep these defaults or you can change them as you see fit.
The Line Style of a Border
To visually control, the borders of a cell or a group of cells, on the Ribbon, click Home. In the Font section, click the arrow of the Borders button and select one of the options:
To programmatically control the borders of a cell or a group of cells, refer to the cell or the group of cells and access its Borders object. This object is accessed as an indexed property.
Example
Range (“C2”).Borders()
In the parentheses of the Borders property, specify the border you want to change. The primary available values are: xlEdgeBottom , xlEdgeTop, xlEdgeLeft, and xlEdgeRight. Sometimes you may have selected a group of cells and you want to take an action on the line(s) between (among) them. To support this, the Borders property can take an index named xlInsideVertical for a vertical border between two cells or an index named xlInsideHorizontal for a horizontal border between the cells.
After specifying the border you want to work on, you must specify the type of characteristic you want to change. For example, you can specify the type of line you want the border to show. To support this, the Borders object is equipped with a property named LineStyle. To specify the type of line you want the border to display, you can assign a value to the LineStyle property. The available values are xlContinuous, xlDash, xlDashDot, xlDashDotDot, xlDot, xlDouble, xlSlantDashDot, and xlLineStyleNone. Therefore, you can assign any of these values to the property. To assist you with this, you can type LineStyle followed by a period and select the desired value from the list that appears:
Example
Sub Border()
Range(“B1:B20”).Borders.LineStyle=xlDot
Range(“B1:B20”).Borders.Color=vbBlue
Range(“B1:B20”).Borders.Weight=3
End sub
Example
Sub Border()
Range(“B1:B20”).Borders.LineStyle=xlDouble
Range(“B1:B20”).Borders.Color=vbred
Range(“B1:B20”).Borders.Weight=4
End sub
Please Watching My Video is Below
No comments:
Post a Comment