In this blog post, you will learn
about how to apply a border and its style in Excel VBA.
Suppose that we have a dataset from
range “A1: B6”, and we want to apply borders in this area by Excel VBA.
First of all, we must know what is a border and style in Excel and how to apply it in the given dataset.
Select the dataset first, where we want to apply the border style and then go to Excel “Home” tab, in the “Font” group.
Click on “Border” icon, see image below:-
Click on the drop-down arrow and
there are multiples of border options, which we can apply in our dataset.
Now we will do all this with the help
of Excel VBA.
See the below image:-
In the above image, we have a range
“A1: B6”, where to apply the border.
Our first code is:-
1. ‘Range
("A1:B6").Borders.LineStyle = xlDot’
Applying this code, dotted lines
appear on the borders of our dataset.
2. Range("A1:B6").Borders.Color
= vbBlue
By writing this line of code, the color of our border changed as ‘Blue’.
In
this method, we can apply the "8 standard colors" of our borderlines.
See the 8 standard colors in the
previous VBA tutorial.
3. Range("A1:B6").Borders.Value
= 4
In
this code I have applied a number (4) for the border style. There is some number
which is assigned for some particular border style.
4. Range("A1:B6").Borders.Weight
= 3
In
this code, we applied “Border. Weight” as 3, border weight is the width or
thickness of the border. And we can apply border weight maximum up to “4”.
5. Range("A1:B6").Borders.LineStyle
= xlContinuous
This
code represents the border style as continuous, i. e continuous line without
any dot or any other style.
6. Range("A1:B6").Borders.LineStyle
= xlDouble
This code represents the double lines as border style.
7. Range("A1:B6").Borders.LineStyle
= xlNone
And in the bottom, if you remove all border-style then write
this code as “xlNone”.
Here in this blog, I have written and described some basic code
to apply the border styles in our dataset.
I hope you find this useful.
Regards
No comments:
Post a Comment