Macro - Clear Borders

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi All,

I know how to clear the contents of cells in a macro,ie.
Range("A1:B50").ClearContents - however can anyone tell me what needs to be
included in a macro to clear "Borders" created around cells for a given range.

I am just getting into creating macros - so if the above is not clear,please
let me know.
Thank you
 
Select a range and:

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 11/21/2007 by James Ravenswood
'

'
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
Selection.Borders(xlEdgeTop).LineStyle = xlNone
Selection.Borders(xlEdgeBottom).LineStyle = xlNone
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
End Sub
 
To account for diagonals revise to this.

Sub test()
With Range("A1:B50")
.Borders.LineStyle = xlNone
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
End With
End Sub


Gord Dibben MS Excel MVP
 
And I just learned something new. I did not realize that my original code did
not remove the diagonals. That being said I can honestly say I have never
used the diagonals... but if I ever do... Thanks Gord
 
Not only doesn't it remove diagonals, it adds diagonals to cells in the range
that don't originally have them.

Set A1:B10 with cell borders and include diagonals.

Run your original macro.

Clears the outside and interior borders in A1:B10 but leaves the diagonals and
also adds them to A11:B50

Note: the diagonals are actually doubled up so if you go to Format>Cell>Borders
you have to click twice to clear them.

Not nice and definitely weird<g>


Gord
 
Spookey... This one darn near fits into JWalk's XL oddities.

This has re-affirmed my desire to just never use diagonals. That being said
many moons from now I am going to break down and use them for some obscure
reason and my code will mess them up. On that day I will (vaguely) recall
this conversation with a sense of (told you so)...
 
@ Gary's Student
@ Jim Thomlinson
@ Gord Dibben

Hi Guys - I have tried them out and they work - thankyou all. The diagonals
is a step too far for me,but I will file it away somewhere .. some day to
called upon in the fullness of time.

FG
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top