LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Lock cells after data entry ?

Hi, I have a shared excel file. I want to prevent users from deleting and
changing entries on it.
I only want them to be able to add new data to the empty cells.
I found a sample code to do that, but whenever I open the file ,
i need to re-run the macro to protect the cells that are not empty.

Sample Code :

Private Sub Worksheet_Change(ByVal Target As Range)

Dim cel As Range

If Not Intersect(Target, Me.[a1:ba2000]) Is Nothing Then
Application.EnableEvents = False
On Error Resume Next
Me.Unprotect "pw"
On Error GoTo 0
For Each cel In Intersect(Target, Me.[a1:ba2000]).Cells
cel.Locked = True
Next
ActiveSheet.EnableSelection = xlUnlockedCells
Me.Protect "pw"
Application.EnableEvents = True
End If

End Sub

Sub ini_lock()
Dim cel As Range

Application.EnableEvents = False
On Error Resume Next
ActiveSheet.Unprotect "pw"
On Error GoTo 0
Cells.Locked = False
For Each cel In Intersect([a1:ba2000], [a1:ba2000])
If cel.Value < "" Or cel.HasFormula = True Then cel.Locked =
True
Next
ActiveSheet.EnableSelection = xlUnlockedCells
ActiveSheet.Protect "pw"
Application.EnableEvents = True

End Sub

How can I make this macro automatically run , when I open the file?
I tried this code, but I still need to go to the macros menu and run macro
manually.

Private Sub Workbook_Open()
Run ini_lock
End Sub


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I lock a cell after data entry so entry can not be changed Verlinde Excel Discussion (Misc queries) 3 April 22nd 10 07:59 PM
Lock format but allow data entry Iriemon Excel Discussion (Misc queries) 0 April 7th 10 07:30 PM
lock cells after entry maximillan via OfficeKB.com Excel Programming 1 April 29th 07 04:34 AM
Lock Row after Data Entry boatnisfun Excel Discussion (Misc queries) 1 March 10th 07 08:03 AM
Lock Cell After Data Entry Ripper Excel Discussion (Misc queries) 1 February 28th 06 08:17 PM


All times are GMT +1. The time now is 11:56 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"