Unable To Set The Linestyle Property Of The Border Class

anwaee2

Board Regular
Joined
Sep 13, 2012
Messages
127
Office Version
  1. 2011
Platform
  1. MacOS
I am having problems with the macro below. It runs fine on Excel for Mac but when I try to run it on Excel for Windows I get the "Unable To Set The Linestyle Property Of The Border Class" error message. I have gone online and tried all the different lines of code i found to no avail. Any help would be greatly appreciated. Thanks in advance for any help I may get.

Code:
Sub Put_Borders_On()
 
Dim LRB1 As Long, LRB2 As Long, LRB3 As Long
Dim LR As Long, r As Long
Dim WS As Worksheet
Set WS = ActiveWorkbook.Worksheets("DataBase")
 
With WS
 
    .Unprotect
 
    For r = 6 To 5000 Step 1
        If Cells(r, 1).Borders(xlEdgeBottom).LineStyle <> xlContinuous Then
        .Range("G21") = r - 1
        Exit For
        End If
    Next r
   
    LR = .Cells(Rows.Count, 1).End(xlUp).Row
    .Range("A5:E" & LR).Select
        .Sort.SortFields.Clear
        .Sort.SortFields.Add Key:=Range( _
            "B5:B" & LR), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortNormal
        .Sort.SortFields.Add Key:=Range( _
            "A5:A" & LR), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortNormal
        With .Sort
            .SetRange Range("A5:E" & LR)
            .Header = xlNo
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
        .Apply
    End With
 
    If Range("G18") = 0 Then
   
        LRB1 = .Range("G21")
        LRB3 = .Cells(Rows.Count, 1).End(xlUp).Row + 2
       
        With .Range("A5:E" & LRB1)
            .Borders.LineStyle = xlNone
            .Interior.Color = RGB(255, 255, 255)
            .Locked = True
        End With
       
        With .Range("A5:E5")
            .Borders(xlEdgeLeft).LineStyle = xlContinuous
            .Borders(xlEdgeBottom).LineStyle = xlContinuous
            .Borders(xlEdgeRight).LineStyle = xlContinuous
            .Borders(xlInsideVertical).LineStyle = xlContinuous
            .Borders(xlInsideHorizontal).LineStyle = xlContinuous
        End With
       
        .Range("A5:E5").Locked = False
        .Range("A5:E5").Interior.Color = RGB(255, 235, 255)
        .Range("A5").Select
  
    Else
        LRB1 = r
        LRB2 = .Cells(Rows.Count, 1).End(xlUp).Row + 1
        'LRB3 = .Cells(Rows.Count, 1).End(xlUp).Row + 2
        With .Range("A5:E" & LRB1)
            .Borders.LineStyle = xlNone
            .Interior.Color = RGB(255, 255, 255)
            .Locked = True
        End With
       
        With .Range("A5:E" & LRB2)
            .Borders(xlEdgeLeft).LineStyle = xlContinuous
            .Borders(xlEdgeBottom).LineStyle = xlContinuous
            .Borders(xlEdgeRight).LineStyle = xlContinuous
            .Borders(xlInsideVertical).LineStyle = xlContinuous
            .Borders(xlInsideHorizontal).LineStyle = xlContinuous
            .Locked = False
        End With
       
        .Range("A" & LRB2 & ":" & "E" & LRB2).Interior.Color = RGB(255, 235, 255)
        .Range("A" & LRB2).Select
    End If
       
    .Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
 
End With
 
End Sub
 

Some videos you may like

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Watch MrExcel Video

Forum statistics

Threads
1,122,224
Messages
5,594,915
Members
413,952
Latest member
JGer

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
Top