VBA question

Emmily

Well-known Member
Joined
Oct 5, 2008
Messages
676
Hi can someone please explain why i am get the below error on

.LineStyle = xlContinuous

Run-Time error 1004
Unable to set the LineStyle property of the border class

Code:
Private Sub Borders()
Dim LastRow As Long
Dim Rng As Range
Dim ShtSummary As Excel.Worksheet
Dim myBorders() As Variant, item As Variant
                myBorders = Array(xlEdgeLeft, _
                                    xlEdgeTop, _
                                    xlEdgeBottom, _
                                    xlEdgeRight, _
                                xlInsideVertical, _
                                xlInsideHorizontal)
                                
For Each item In myBorders
Set ShtSummary = Sheets(gstrSummary)
   With ShtSummary
        With .Range("A5:D5").Borders(item)
            .LineStyle = xlContinuous
            .Weight = xlMedium
            .ColorIndex = xlAutomatic
        End With
        LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
        Set Rng = .Range("A6:D" & LastRow)
        With Rng.Borders(item)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = 0
        End With
   End With
Next item
 
End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
The code you posted runs without error for me and appears to do what it is intended to do, provided I change the sheet name gstrSummary to the name of the sheet I tried it on.
 
Upvote 0
Edit: Oops, didn't see JoeMo's response :)

I copied your code and it ran without error (after I set gstrSummary to be the name of one of my worksheets)
 
Upvote 0
See the link Sulakvea posted - it's a known error in Excel 2002.
 
Upvote 0
Try this modification
Rich (BB code):
If LastRow > 6 Or item < 12 Then
    Set Rng = .Range("A6:D" & LastRow)
    With Rng.Borders(item)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = 0
    End With
End If
 
Upvote 0

Forum statistics

Threads
1,224,503
Messages
6,179,136
Members
452,890
Latest member
Nikhil Ramesh

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top