Tech Support Guy banner
Status
Not open for further replies.
1 - 3 of 3 Posts

·
Registered
Joined
·
2,895 Posts
Discussion Starter · #1 ·
I have created a pivot table within an Excel 2007 workbook.

I am trying to apply the following code to the pivot table:

Code:
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)

    Application.ScreenUpdating = False
    
    Dim LastRow As Long, iRow As Long

Set ws2 = ActiveWorkbook.Sheets("Pivot")
    
    With ws2.Range("A2:B" & ws2.Rows.Count)
        LastRow = .Find(What:="*", after:=.Cells(1, 1), LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    End With
    
    iRow = LastRow

        ws2.Range("A3:B" & iRow).Borders(xlDiagonalDown).LineStyle = xlNone
        ws2.Range("A3:B" & iRow).Borders(xlDiagonalUp).LineStyle = xlNone
        ws2.Range("A3:B" & iRow).Borders(xlEdgeLeft).LineStyle = xlContinuous
        ws2.Range("A3:B" & iRow).Borders(xlEdgeLeft).Weight = xlThin
        ws2.Range("A3:B" & iRow).Borders(xlEdgeLeft).ColorIndex = xlAutomatic
        ws2.Range("A3:B" & iRow).Borders(xlEdgeTop).LineStyle = xlContinuous
        ws2.Range("A3:B" & iRow).Borders(xlEdgeTop).Weight = xlThin
        ws2.Range("A3:B" & iRow).Borders(xlEdgeTop).ColorIndex = xlAutomatic
        ws2.Range("A3:B" & iRow).Borders(xlEdgeBottom).LineStyle = xlContinuous
        ws2.Range("A3:B" & iRow).Borders(xlEdgeBottom).Weight = xlThin
        ws2.Range("A3:B" & iRow).Borders(xlEdgeBottom).ColorIndex = xlAutomatic
        ws2.Range("A3:B" & iRow).Borders(xlEdgeRight).LineStyle = xlContinuous
        ws2.Range("A3:B" & iRow).Borders(xlEdgeRight).Weight = xlThin
        ws2.Range("A3:B" & iRow).Borders(xlEdgeRight).ColorIndex = xlAutomatic
        ws2.Range("A3:B" & iRow).Borders(xlInsideVertical).LineStyle = xlContinuous
        ws2.Range("A3:B" & iRow).Borders(xlInsideVertical).Weight = xlThin
        ws2.Range("A3:B" & iRow).Borders(xlInsideVertical).ColorIndex = xlAutomatic
        ws2.Range("A3:B" & iRow).Borders(xlInsideHorizontal).LineStyle = xlContinuous
        ws2.Range("A3:B" & iRow).Borders(xlInsideHorizontal).Weight = xlThin
        ws2.Range("A3:B" & iRow).Borders(xlInsideHorizontal).ColorIndex = xlAutomatic

Application.ScreenUpdating = False
end sub
However, I get the following error:

Run-time error '1004': Unable to set the LineStyle property of the border class.
 
1 - 3 of 3 Posts
Status
Not open for further replies.
Top