Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Lock cell and reprotect sheet after save

I have a spreadsheet that tracks performance. Some info is put in by many
different users. Other info is put in by our Admin team. All the cells that
our Admin team updates is locked and the sheet is always protected.
Is there a macro that will lock the cells that the users make changes to
once they have entered and saved the inforation - I am hoping to prevent
changes/deletions once the information has been entered.

I am a novice at vba.
Thankx in advance
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Lock cell and reprotect sheet after save

Hi Clark,

Try something like:

'=============
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim SH As Worksheet
Dim rng As Range
Const PWORD As String = "ABC" '<<=== CHANGE

Set SH = Me.Sheets("Sheet1") '<<=== CHANGE

With SH
On Error Resume Next
Set rng = SH.Cells.SpecialCells(xlCellTypeConstants)
On Error GoTo 0

If Not rng Is Nothing Then
.Unprotect Password:=PWORD
.Cells.Locked = False
rng.Cells.Locked = True
.Protect Password:=PWORD
End If
End With
End Sub
'<<=============

This is workbook event code and should be pasted into the workbook's
ThisWorkbook module *not* a standard module or a sheet module:

Right-click the Excel icon on the worksheet
(or the icon to the left of the File menu if your workbook is maximised)
Select 'View Code' from the menu and paste the code.
Alt-F11 to return to Excel.


---
Regards,
Norman


"clarknv" wrote in message
...
I have a spreadsheet that tracks performance. Some info is put in by many
different users. Other info is put in by our Admin team. All the cells
that
our Admin team updates is locked and the sheet is always protected.
Is there a macro that will lock the cells that the users make changes to
once they have entered and saved the inforation - I am hoping to prevent
changes/deletions once the information has been entered.

I am a novice at vba.
Thankx in advance



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Lock cell and reprotect sheet after save

Hi Clark,

Replace my suggested code with the following version:

'=============
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim SH As Worksheet
Dim rng As Range
Const PWORD As String = "ABC" '<<=== CHANGE

Set SH = Me.Sheets("Sheet1") '<<=== CHANGE

With SH
.Unprotect Password:=PWORD
On Error Resume Next
Set rng = SH.Cells.SpecialCells(xlCellTypeConstants)
On Error GoTo 0

If Not rng Is Nothing Then
.Cells.Locked = False
rng.Cells.Locked = True
.Protect Password:=PWORD
End If
End With
End Sub
'<<=============



---
Regards,
Norman


Reply
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
How can I lock a picture with a cell so it sorts with the sheet Habby Excel Discussion (Misc queries) 1 January 22nd 10 05:16 PM
Lock Hyperlink to cell in different sheet Regina[_2_] Excel Discussion (Misc queries) 5 February 24th 09 12:41 PM
Protect then reprotect using macro checkQ Excel Discussion (Misc queries) 2 October 13th 07 05:12 PM
how do i lock a cell? to save formula or function in it? Ajay Upmaneu Excel Discussion (Misc queries) 1 July 4th 06 10:17 AM
lock tab in sheet 2 until cell in sheet one is completed john tempest Excel Worksheet Functions 7 November 24th 05 08:45 AM


All times are GMT +1. The time now is 01:53 PM.

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

About Us

"It's about Microsoft Excel"