changing border style


Posted by chirag modi on June 10, 2001 10:14 PM

Hi All,
I've a problem with changing the borderstyle through VB code in Excel(VBA).For a selected range in excel I want to change the borderstyle of that range alone to normal.
Kindly help me out as how to proceed with.




Posted by Ben O. on June 11, 2001 11:01 AM

I'm not sure what you mean by normal borders, but you can customize the code with your border preferences. Here's an example:

Sub NormalBorders()
With Selection
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
.Borders(xlEdgeLeft).LineStyle = xlNone
.Borders(xlEdgeTop).LineStyle = xlNone
.Borders(xlEdgeBottom).LineStyle = xlNone
.Borders(xlEdgeRight).LineStyle = xlNone
.Borders(xlInsideVertical).LineStyle = xlNone
.Borders(xlInsideHorizontal).LineStyle = xlNone
End With
End Sub

For a single line border use:

.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlEdgeBottom).LineStyle = xlThin

Or why not just record a macro, making the border style exactly how you want it, and then use that code?

-Ben