• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

AUTO PROTECT CELLS AFTER ENTERING DATA ONCE SAVED

SARJIL VHORA

New Member
Hi,

I want to protect few cells such away that users can not edit data in few cells once file saved. i have hereby attached my excel sheet, i want to apply above protection in yellow highlighted raw.
please help me.. is it possible ??
 

Attachments

  • INTERNAL CALL BOOKING SHEET.xlsm
    54.5 KB · Views: 62
Hi,

You have highlighted two columns

1) Do you wan to protect whole column or only the cells which are not blank

2) This can be done only through macro. Would it be ok?
 
Hi,

Try the below code in workbook module

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
 
Sheet1.Unprotect Password:="password"
 
Lr = Rows.Count
Range("G3:G" & Lr).Locked = True
Range("K3:K" & Lr).Locked = True
   
Sheet1.Protect Password:="password"
 
 
   
End Sub
 
Go to VBA screen and left side of the screen you can see 'Workbook'

Double click on it and on the right side paste the above code
 
Hi,

The whole sheet is password protected

You need to unlock the cells which ever you need to be open even after sheet is protected with password

To do this select all the required cells to be unlocked, righclik and go to format,

In the format pop-up goto Protection Tab, Under protection tab uncheck the option 'Locked'
 
Hi,
still my problem is not solved... what i want ???
- if user enters data in yellow highlighted cells and saves files then he can not allowed to re-enter data in old cells but he can enter data in new cells.
 
Hi,

Find the below code


Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Application.ScreenUpdating = False
 
Sheet1.Unprotect Password:="password"
Lr = Rows.Count
 
Range("G3:G" & Lr).Select
Selection.SpecialCells(xlCellTypeConstants, 23).Select
Selection.Locked = True
 
Range("G3:G" & Lr).Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.Locked = False
 
 
Range("K3:K" & Lr).Select
Selection.SpecialCells(xlCellTypeConstants, 23).Select
Selection.Locked = True
 
Range("K3:K" & Lr).Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.Locked = False
 
Sheet1.Protect Password:="password"
 
Application.ScreenUpdating = True
 
End Sub
 
Try below code

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
 
on error exit sub
Application.ScreenUpdating = False
Sheet1.Unprotect Password:="password"
Lr = Rows.Count
Range("G3:G" & Lr).Select
Selection.SpecialCells(xlCellTypeConstants, 23).Select
Selection.Locked = True
Range("G3:G" & Lr).Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.Locked = False
Range("K3:K" & Lr).Select
Selection.SpecialCells(xlCellTypeConstants, 23).Select
Selection.Locked = True
Range("K3:K" & Lr).Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.Locked = False
Sheet1.Protect Password:="password"
Application.ScreenUpdating = True
End Sub
 
This will work

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
On Error Goto Err
Application.ScreenUpdating = False
Sheet1.Unprotect Password:="password"
Lr = Rows.Count
Range("G3:G" & Lr).Select
Selection.SpecialCells(xlCellTypeConstants, 23).Select
Selection.Locked = True
Range("G3:G" & Lr).Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.Locked = False
Range("K3:K" & Lr).Select
Selection.SpecialCells(xlCellTypeConstants, 23).Select
Selection.Locked = True
Range("K3:K" & Lr).Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.Locked = False
Sheet1.Protect Password:="password"
Application.ScreenUpdating = True
 
Err:
Exit Sub
End Sub
 
Error during saving is solved but not fulfill prime requirement.. still user can edit previous data in yellow highlighted cells
 
Hi,
one problem I am facing while using this sheet is user can not use option such as autofilter etc.....
is it provision to enable these ?? i have tried to enable by marking tick on protect sheet tab but it works untill i save sheets. afterwards user can not use..
upload_2014-10-10_20-10-58.png
 
Hi,

Use the below code

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
On Error Goto Err
Application.ScreenUpdating = False
Sheet1.Unprotect Password:="password"
Lr = Rows.Count
Range("G3:G" & Lr).Select
Selection.SpecialCells(xlCellTypeConstants, 23).Select
Selection.Locked = True
Range("G3:G" & Lr).Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.Locked = False
Range("K3:K" & Lr).Select
Selection.SpecialCells(xlCellTypeConstants, 23).Select
Selection.Locked = True
Range("K3:K" & Lr).Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.Locked = False
Sheet1.Protect Password:="password", AllowFiltering:=True
Application.ScreenUpdating = True
Err:
Exit Sub
End Sub
 
Back
Top