Highlighting Rows in Protected worksheet

AKMAKM

New Member
Joined
Jan 13, 2022
Messages
10
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
I am using a highlight active row on my worksheet by VBA code :

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("a8:cu200")) Is Nothing Then
Range("cx5").Value = Target.Row
End If
End Sub


And using the conditional formatting rules manager :

1645975041438.png



Unfortunately when I protect the sheet with password "1234" from Review section (protect sheet) , I get the below message and the highlight row order stopped to work

1645974311534.png


1645974788384.png


Thank you in advance to help me to solve this issue.
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Try:
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Not Intersect(Target, Range("a8:cu200")) Is Nothing Then
        ActiveSheet.Unprotect Password:="1234"
        Range("cx5").Value = Target.Row
        ActiveSheet.Protect Password:="1234"
    End If
End Sub
Do you actually need to highlight the row using conditional formatting? The macro could do that for you without the need for conditional formatting.
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Not Intersect(Target, Range("a8:cu200")) Is Nothing Then
        ActiveSheet.Unprotect Password:="123"
        Rows(Target.Row).Interior.ColorIndex = 6
        ActiveSheet.Protect Password:="123"
    End If
End Sub
 
Upvote 0
Solution
if you add this in Thisworkbook, save the workbook, close and reopen, VBA can do everything without password
VBA Code:
Private Sub Workbook_Open()
     Sheets("mySheet").Protect Password:="123", userinterfaceonly:=True
End Sub
 
Upvote 0
Thank you gentlemen for your kind help and assistance.
The VBA code work perfectly. ?
 
Upvote 0

Forum statistics

Threads
1,214,632
Messages
6,120,649
Members
448,975
Latest member
sweeberry

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