VBA: Border not working when sheet protected

jorgedshuler

New Member
Joined
Mar 6, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
The following code does not work when my sheet is protected. However, it works perfectly fine when the sheet is unprotected.

Code:
Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
Range("N2:U2").Borders(xlEdgeTop).LineStyle = xlContinuous
Range("N5:U5").Borders(xlEdgeBottom).LineStyle = xlContinuous
Range("N2,N3,N4,N5").Borders(xlEdgeLeft).LineStyle = xlContinuous
Range("U2,U3,U4,U5").Borders(xlEdgeRight).LineStyle = xlContinuous
Range("N2").Value = "ISSUED"
Range("N5").Value = Date
Else: Range("N2:U2").Borders(xlEdgeTop).LineStyle = xlLineStyleNone
Range("N5:U5").Borders(xlEdgeBottom).LineStyle = xlLineStyleNone
Range("N2,N3,N4,N5").Borders(xlEdgeLeft).LineStyle = xlLineStyleNone
Range("U2,U3,U4,U5").Borders(xlEdgeRight).LineStyle = xlLineStyleNone
Range("N2").Value = ""
Range("N5").Value = ""
End If
End Sub
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
at the beginning of the code unprotect the sheet with

activesheet.unprotect "abc"
(change abc for your password)
at the end of the code protect it again with
activesheet.protect "abc"
 
Upvote 0
Solution

Forum statistics

Threads
1,215,767
Messages
6,126,774
Members
449,336
Latest member
p17tootie

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