VBA - Lock rows in a table while still being able to filter/sort.

Status
Not open for further replies.

cmcev

New Member
Joined
Mar 30, 2022
Messages
2
Office Version
  1. 2019
Platform
  1. Windows
Hi,

I'm currently using the following code to lock Row's A:P. I have a dropdown in column R to select 'Yes'. Once this is selected I have conditional formatting changing the row to grey to show it shouldnt be edited. However in doing so, once the rows are locked I can no longer filter or sort the table.

Any advice would be great.

Thanks,
C

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("E1")) Is Nothing Then
ActiveSheet.Name = ActiveSheet.Range("E1")
End If
If Intersect(Target, Range("R:R")) Is Nothing Then Exit Sub
Select Case Target.Value
Case "Yes"
Range("A" & Target.Row & ":P" & Target.Row).Locked = True
UserInterfaceOnly = True
AllowSorting = True
AllowFiltering = True
Case Else
Range("A" & Target.Row & ":P" & Target.Row).Locked = False
End Select
End Sub
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Status
Not open for further replies.

Forum statistics

Threads
1,214,646
Messages
6,120,715
Members
448,985
Latest member
chocbudda

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