Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
In Calif
 
Posts: n/a
Default Lock Cells to Prevent Changes

Hi Everybody,

Is there a way to dynamcally to protect a cell after the user's input upon
saving the file? What I am looking for is to prevent users from making
changes once the file is saved after their input. I am using this to track
vacation, personal day off & sick day dates and hours taken. The users are
given a date col & hrs col to input the date, I would like the input be
protected once the file is saved but the rest of the
empty cells in the col are still unprotected for future input.

Vac Date Vac Hrs.
1/23/2005 8 (Theses entries are protected after saving the file.)
2/23/2005 4
(Blank cells in the range are left
unprotected.)

Thanks for your time and help!!!

In Calif

  #2   Report Post  
Jim Cone
 
Posts: n/a
Default

In,
This would require a macro to be automatically run
just before the workbook is saved.
Is that a suitable?

Jim Cone
San Francisco, USA

"In Calif"
wrote in message
...
Hi Everybody,
Is there a way to dynamcally to protect a cell after the user's input upon
saving the file? What I am looking for is to prevent users from making
changes once the file is saved after their input. I am using this to track
vacation, personal day off & sick day dates and hours taken. The users are
given a date col & hrs col to input the date, I would like the input be
protected once the file is saved but the rest of the
empty cells in the col are still unprotected for future input.

Vac Date Vac Hrs.
1/23/2005 8 (Theses entries are protected after saving the file.)
2/23/2005 4
(Blank cells in the range are left
unprotected.)

Thanks for your time and help!!!

In Calif

  #3   Report Post  
In Calif
 
Posts: n/a
Default

Jim,

Thanks, how do you do that?

In Calif

"Jim Cone" wrote:

In,
This would require a macro to be automatically run
just before the workbook is saved.
Is that a suitable?

Jim Cone
San Francisco, USA

"In Calif"
wrote in message
...
Hi Everybody,
Is there a way to dynamcally to protect a cell after the user's input upon
saving the file? What I am looking for is to prevent users from making
changes once the file is saved after their input. I am using this to track
vacation, personal day off & sick day dates and hours taken. The users are
given a date col & hrs col to input the date, I would like the input be
protected once the file is saved but the rest of the
empty cells in the col are still unprotected for future input.

Vac Date Vac Hrs.
1/23/2005 8 (Theses entries are protected after saving the file.)
2/23/2005 4
(Blank cells in the range are left
unprotected.)

Thanks for your time and help!!!

In Calif


  #4   Report Post  
Jim Cone
 
Posts: n/a
Default

In,

You paste the following code in the "ThisWorkbook" module
of the workbook. You also make the noted changes/corrections
to the code after pasting.
Press Alt + F11 to get to the Visual Basic Editor (where the code goes).
Press Ctrl + R to view the project explorer (like windows explorer)
Look for your workbook project.
Expand it to show "ThisWorkbook".
Double click on that.

If you're new to macros, you may want to read:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Prudence dictates that you make a backup copy of your
workbook, before proceeding.

Jim Cone
San Francisco, USA

'------------------------------------------------
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
'Jim Cone - San Francisco, USA - Sept. 13, 2005
'Assumes worksheet in question is named "Specify".
'Assumes Column "5" is the column for user input.
'Assumes the worksheet password is "Password"
'Unlocks cells in column 5 that are below the last entry in that column.
'Locks all cells in column 5 above (and including) the last entry.
'Protects the worksheet.

On Error GoTo SaveErr
Dim rngToProtect As Excel.Range
Dim rngBottom As Excel.Range
Application.EnableEvents = False
'REPLACE "SPECIFY" WITH CORRECT SHEET NAME
With ThisWorkbook.Worksheets("Specify")
'REPLACE "5" WITH CORRECT COLUMN NUMBER IN 3 PLACES.
Set rngBottom = .Cells(Rows.Count, 5).End(xlUp)
Set rngToProtect = .Range(.Cells(1, 5), rngBottom)
'REPLACE "PASSWORD" WITH CORRECT PASSWORD IN 2 PLACES.
.Unprotect "Password"
rngToProtect.Locked = True
.Range(rngBottom(2, 1), .Cells(Rows.Count, 5)).Locked = False
.Protect "Password"
End With

Set rngToProtect = Nothing
Set rngBottom = Nothing
Application.EnableEvents = True
Exit Sub

SaveErr:
MsgBox "Error " & Err.Number & " - " & Err.Description
Cancel = True
Application.EnableEvents = True
End Sub
'-----------------------------------------------


"In Calif"
wrote in message

Jim,
Thanks, how do you do that?
In Calif


"Jim Cone" wrote:
In,
This would require a macro to be automatically run
just before the workbook is saved.
Is that a suitable?
Jim Cone
San Francisco, USA

"In Calif"
wrote in message
...
Hi Everybody,
Is there a way to dynamcally to protect a cell after the user's input upon
saving the file? What I am looking for is to prevent users from making
changes once the file is saved after their input. I am using this to track
vacation, personal day off & sick day dates and hours taken. The users are
given a date col & hrs col to input the date, I would like the input be
protected once the file is saved but the rest of the
empty cells in the col are still unprotected for future input.
Vac Date Vac Hrs.
1/23/2005 8 (Theses entries are protected after saving the file.)
2/23/2005 4
(Blank cells in the range are left
unprotected.)
Thanks for your time and help!!!
In Calif

  #5   Report Post  
In Calif
 
Posts: n/a
Default

Thanks Jim, I give it a try!

In Calif

"Jim Cone" wrote:

In,

You paste the following code in the "ThisWorkbook" module
of the workbook. You also make the noted changes/corrections
to the code after pasting.
Press Alt + F11 to get to the Visual Basic Editor (where the code goes).
Press Ctrl + R to view the project explorer (like windows explorer)
Look for your workbook project.
Expand it to show "ThisWorkbook".
Double click on that.

If you're new to macros, you may want to read:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Prudence dictates that you make a backup copy of your
workbook, before proceeding.

Jim Cone
San Francisco, USA

'------------------------------------------------
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
'Jim Cone - San Francisco, USA - Sept. 13, 2005
'Assumes worksheet in question is named "Specify".
'Assumes Column "5" is the column for user input.
'Assumes the worksheet password is "Password"
'Unlocks cells in column 5 that are below the last entry in that column.
'Locks all cells in column 5 above (and including) the last entry.
'Protects the worksheet.

On Error GoTo SaveErr
Dim rngToProtect As Excel.Range
Dim rngBottom As Excel.Range
Application.EnableEvents = False
'REPLACE "SPECIFY" WITH CORRECT SHEET NAME
With ThisWorkbook.Worksheets("Specify")
'REPLACE "5" WITH CORRECT COLUMN NUMBER IN 3 PLACES.
Set rngBottom = .Cells(Rows.Count, 5).End(xlUp)
Set rngToProtect = .Range(.Cells(1, 5), rngBottom)
'REPLACE "PASSWORD" WITH CORRECT PASSWORD IN 2 PLACES.
.Unprotect "Password"
rngToProtect.Locked = True
.Range(rngBottom(2, 1), .Cells(Rows.Count, 5)).Locked = False
.Protect "Password"
End With

Set rngToProtect = Nothing
Set rngBottom = Nothing
Application.EnableEvents = True
Exit Sub

SaveErr:
MsgBox "Error " & Err.Number & " - " & Err.Description
Cancel = True
Application.EnableEvents = True
End Sub
'-----------------------------------------------


"In Calif"
wrote in message

Jim,
Thanks, how do you do that?
In Calif


"Jim Cone" wrote:
In,
This would require a macro to be automatically run
just before the workbook is saved.
Is that a suitable?
Jim Cone
San Francisco, USA

"In Calif"
wrote in message
...
Hi Everybody,
Is there a way to dynamcally to protect a cell after the user's input upon
saving the file? What I am looking for is to prevent users from making
changes once the file is saved after their input. I am using this to track
vacation, personal day off & sick day dates and hours taken. The users are
given a date col & hrs col to input the date, I would like the input be
protected once the file is saved but the rest of the
empty cells in the col are still unprotected for future input.
Vac Date Vac Hrs.
1/23/2005 8 (Theses entries are protected after saving the file.)
2/23/2005 4
(Blank cells in the range are left
unprotected.)
Thanks for your time and help!!!
In Calif


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
Can I lock a set of cells in a worksheet? puneetarora_12 Excel Discussion (Misc queries) 3 July 8th 05 11:07 PM
How secure is the "lock cells" function? The rose Excel Worksheet Functions 2 April 26th 05 08:12 PM
How do you prevent users from pasting over validated cells? LCK Excel Discussion (Misc queries) 3 March 2nd 05 09:28 PM
Can I use the grouping and lock and protect cells bfisher Excel Discussion (Misc queries) 1 January 11th 05 10:55 PM
Convert data type of cells to Text,Number,Date and Time Kevin Excel Worksheet Functions 1 December 31st 04 12:57 PM


All times are GMT +1. The time now is 04:13 AM.

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"