VBA. Protect some rows and colums in worksheet

Ambre

New Member
Joined
Sep 12, 2013
Messages
23
Dear all,

This is my code in order to protect some rows and columns of my sheet.

Rich (BB code):
Sheets("Purchasing Plan").Select
ActiveSheet.Unprotect "PJMS"
Cells.Select
Selection.EntireColumn.Hidden = False 
Selection.EntireRow.Hidden = False
On Error Resume Next
    ActiveSheet.ShowAllData 
On Error GoTo 0 
Rows("1:14").Select 
Selection.Locked = True
Selection.FormulaHidden = False
Range("A:E,H:H,K:T,CN:CS,CV:CW").Select 
Selection.Locked = True
Selection.FormulaHidden = False
ActiveSheet.Protect "PJMS", DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFormattingColumns:=True, AllowFormattingRows:=True, AllowSorting:= True, AllowFiltering:=True 'protection de la feuille
Range("A1").Select


Then in the sheet, I cannot do anything in any cell because I am told the sheet is protected.
I though doing means that I am only protecting the cells I want and this is also what is suggested in this page:Lock only a few cells on a worksheet - Excel - Office.com
I did what they suggest to compare, recorded the macro and it gave me something similar to my code so I don't know where is my mistake.

Any ideas?

Thank you :)
Ambre
 
Last edited:

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
The code you show doesn't unlock the rest of the cells on the sheet.

Add a line to set Cells.Locked=False
before locking specific cells
 
Upvote 0
Thank you Jerry! It works.
But in the cells in which there is a drop down list , I do not see the choices anymore, the list does not appear. I see only the arrow.
I click nothing happens (and I do not have an error message). In the tab Data, many options are in grey (not possible to use) like data validation, filter etc.
Do I have to add something XXX=true or is it not related?
(I am a beginner at vba)

Ambre
 
Upvote 0

Forum statistics

Threads
1,215,334
Messages
6,124,319
Members
449,154
Latest member
pollardxlsm

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