Apply auto filter and Lock

Halley yenn

New Member
Joined
Mar 17, 2021
Messages
32
Office Version
  1. 365
Platform
  1. Windows
Hi Folks,

Iam using the below code to open files in the folder and Lock from Column C to Column N and leave Column A and B unlocked, but I need to apply autofilter in the first row of each file and then lock
Column C2 to Column N& Last row.

Can someone help me here??


Option Explicit
Option Compare Text
Sub CellLocking()

Dim FSO As Object, MyFolder As Object
Dim fname As String, fpath As String, pwrd As String
Dim wb As Variant
Dim ws As Worksheet

Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual

pwrd = ("GRUG")
fpath = "enter you folderpath here" ' change as required

Set FSO = CreateObject("scripting.FileSystemObject")
Set MyFolder = FSO.GetFolder(fpath)

For Each wb In MyFolder.Files

If wb.name Like "*.xl*" Then
Set wb = Workbooks.Open(fpath & "\" & wb.name)
For Each ws In wb.Worksheets

ws.Range("A:B").Locked = False
ws.Range("C:N").Locked = True
ws.Protect (pwrd)

Next ws

End If
wb.Save
Next wb

Application.ScreenUpdating = True
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
End Sub




KR,
H
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Forum statistics

Threads
1,215,055
Messages
6,122,902
Members
449,097
Latest member
dbomb1414

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