Are the cells locked before running the macro, from what I gather you would require two pieces of code - one to unlock, and one to lock. Might make it easier if you could name your range
This unlocks locked cells
Code:
Sub unlock_cells()
Range("T10:T14,T17:T19,AD10:AD11").Select
Selection.Locked = False
End Sub
This locks cells
Code:
Sub lock_cells()
Range("T10:T14,T17:T19,AD10:AD11").Select
Selection.Locked = True
End Sub
Thanks Andrew and PS1! I am almost on the peak of that. But, this gives me a problem.
The file is originally protected/locked. This is the VBA code that I got by recording the macro:
Sub Macro1()
'
' Macro1 Macro
' unlock and lock
'
' Keyboard Shortcut: Ctrl+Shift+L
'
Range("T10:T14,T17:T19,AD10:AD11").Select
Range("AD10").Activate
ActiveSheet.Unprotect
Selection.Locked = False
Selection.FormulaHidden = False
Range("X24").Select
ActiveWorkbook.Save
Range("T10:T14,T17:T19,AD10:AD11").Select
Range("AD10").Activate
Selection.Locked = True
Selection.FormulaHidden = False
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True, AllowInsertingColumns:=True, AllowInsertingRows _
:=True, AllowInsertingHyperlinks:=True, AllowDeletingColumns:=True, _
AllowDeletingRows:=True, AllowSorting:=True, AllowFiltering:=True, _
AllowUsingPivotTables:=True
Range("V26").Select
ActiveWorkbook.Save
End Sub
I would like to program this file as:
1. Originally locked.
2. When the command is entered (Ctrl Shift L), the only cells that will be unlocked are those given cells.
3. After saving, the file will be back to original state which is locked.
It really gives me a headache. I very thankful for your help and support. I am eager to learn this macro thing in excel. Thank you very much guys!