View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jay Jay is offline
external usenet poster
 
Posts: 671
Default Formatting a Pivot Table

Hi NevilleT-

I can't reproduce your error; the code works fine on a test pivot table (as
you've described for your other sheets). I'd suggest converting your code as
follows to report the cell address where the error occurs; that might provide
us with a clue about the cause. Does the error occur when formatting all
cells or just in a particular column or row? Use Ctrl-Break if to stop this
procedure if all cells seem to be causing the error (so you don't have to
respond to ~1200 error messages...).

Sub NevilleT()

Set rng = ActiveSheet.Range("A5:B600")

For Each cel In rng
On Error GoTo errorReport
cel.Interior.ColorIndex = xlNone
cel.Borders(xlDiagonalDown).LineStyle = xlNone ' Error occurs here
cel.Borders(xlDiagonalUp).LineStyle = xlNone
On Error GoTo 0
nextCel:
Next 'cel

normalExit:
Exit Sub

errorReport:
MsgBox "An error occurred when formatting cell " & cel.Address
Resume nextCel

End Sub

----
Jay




"NevilleT" wrote:

I posted this message before but didn't resolve it. I have a pivot table I
am trying to format. The sheet is unprotected and the code fails with an
error

"Unable to set the linestyle property of the border class"

It does however work correctly on other worksheets in the same workbook.

Dim rng As Range

Set rng = ActiveSheet.Range("A5:B600")
rng.Interior.ColorIndex = xlNone
rng.Borders(xlDiagonalDown).LineStyle = xlNone ' Error occurs here
rng.Borders(xlDiagonalUp).LineStyle = xlNone