ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Clear borders macro not working in Excel 2007 but works fine in 20 (https://www.excelbanter.com/excel-programming/412324-clear-borders-macro-not-working-excel-2007-but-works-fine-20-a.html)

RyanH

Clear borders macro not working in Excel 2007 but works fine in 20
 
For some reason when I run this macro in Excel 2003 it works just fine. But
when I try to run it in Excel 2007 I get an Error indicated below. Anyone
have any ideas why?

Sub ClearRange ()

'clears all borders
With Range("B" & ActiveCell.Row, "H" & ActiveCell.Row + 30)
Error = .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

Jim Rech

Clear borders macro not working in Excel 2007 but works fine in 20
 
Works here. Worksheet isn't protected, etc.?

--
Jim
"RyanH" wrote in message
...
| For some reason when I run this macro in Excel 2003 it works just fine.
But
| when I try to run it in Excel 2007 I get an Error indicated below. Anyone
| have any ideas why?
|
| Sub ClearRange ()
|
| 'clears all borders
| With Range("B" & ActiveCell.Row, "H" & ActiveCell.Row + 30)
| Error = .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



Bernard Liengme

Clear borders macro not working in Excel 2007 but works fine in 20
 
Your macro worked just fine for me.
Try it with a new workbook
best wishes
--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"RyanH" wrote in message
...
For some reason when I run this macro in Excel 2003 it works just fine.
But
when I try to run it in Excel 2007 I get an Error indicated below. Anyone
have any ideas why?

Sub ClearRange ()

'clears all borders
With Range("B" & ActiveCell.Row, "H" & ActiveCell.Row + 30)
Error = .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





All times are GMT +1. The time now is 03:41 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com