Remove borders in range

K

Karen53

Hi,

I am trying to clear any cells having borders within a range of their top
and bottom borders. I have the following code:

Sub TroubleTktsClear()

With shtTroubleTickets.Range("B5:B6000")
.Borders(xlEdgeTop).LineStyle = xlNone
.Borders(xlEdgeBottom).LineStyle = xlLineStyleNone
End With

With shtTroubleTickets.Range("A4:B6000")
.ClearContents
End With

End Sub

The contents are clearing but the borders are not clearing. As you can see,
I have tried it with xlNone and xlLineStyleNone and neither is working. I
have checked enableevents is true as is screenupdating.

Have I missed something?
 
P

Peter T

Do you mean you want to clear all horizontal borders, if so include the
following

On Error Resume Next
.Borders(xlInsideHorizontal).LineStyle = xlNone
On Error GoTo 0

Unless you know the range will have at least two rows the line will error,
hence on error resume next (similarly for inside vertical borders)

xlNone and xlLineStyleNone return the same constant, -4142

ClearContents does not remove formats, use ClearFormats or Clear to remove
contents and formats

Regards,
Peter T
 
K

Karen53

Thank you, Peter!
--
Thanks for your help.
Karen53


Peter T said:
Do you mean you want to clear all horizontal borders, if so include the
following

On Error Resume Next
.Borders(xlInsideHorizontal).LineStyle = xlNone
On Error GoTo 0

Unless you know the range will have at least two rows the line will error,
hence on error resume next (similarly for inside vertical borders)

xlNone and xlLineStyleNone return the same constant, -4142

ClearContents does not remove formats, use ClearFormats or Clear to remove
contents and formats

Regards,
Peter T
 

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

Top