Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi
I have a bit of a quandary. I would like to know if it is possible to lock cells once the Enter / Return Key has been pressed or the cursor has been moved from the cell. I don't care if it is Macro or VBA as long as the cell can be locked. A simple example would be were you enter data in say cell C5, press Enter. I would like to lock that cell from being edited with the exception of Administrators. Many thanks in advance for any help I get Peter (UK) |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You can have it lock the cell with an event proceedure, although that
won't do you much good without protecting the sheet. I think what you're asking is; Is there a way to prevent someone from editing a cell once they enter data in to that cell? And the short answer to that is: No. Rob On May 1, 12:06 pm, "Peter W Soady \(UK\)" wrote: Hi I have a bit of a quandary. I would like to know if it is possible to lock cells once the Enter / Return Key has been pressed or the cursor has been moved from the cell. I don't care if it is Macro or VBA as long as the cell can be locked. A simple example would be were you enter data in say cell C5, press Enter. I would like to lock that cell from being edited with the exception of Administrators. Many thanks in advance for any help I get Peter (UK) |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Peter
Private Sub Worksheet_Change(ByVal Target As Excel.Range) On Error GoTo enditall Application.EnableEvents = False 'for a single cell............ If Target.Address = "$C$5" Then 'For a range 'If Not Application.Intersect(Range("A1:A20"), Target) Is Nothing Then 'for a column.............. 'If Target.Cells.Column = 3 Then ActiveSheet.Unprotect Password:="justme" If Target.Value < "" Then Target.Locked = True End If End If enditall: Application.EnableEvents = True ActiveSheet.Protect Password:="justme", DrawingObjects:=True, _ Contents:=True, Scenarios:=True End Sub This is sheet event code. Right-click on the sheet tab and "View Code" Copy/paste into that sheet module. NOTE: first select all cells and Format to "Unlocked" Gord Dibben MS Excel MVP On Tue, 1 May 2007 18:06:08 +0100, "Peter W Soady \(UK\)" wrote: Hi I have a bit of a quandary. I would like to know if it is possible to lock cells once the Enter / Return Key has been pressed or the cursor has been moved from the cell. I don't care if it is Macro or VBA as long as the cell can be locked. A simple example would be were you enter data in say cell C5, press Enter. I would like to lock that cell from being edited with the exception of Administrators. Many thanks in advance for any help I get Peter (UK) |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On May 1, 1:03 pm, Gord Dibben <gorddibbATshawDOTca wrote:
Peter Private Sub Worksheet_Change(ByVal Target As Excel.Range) On Error GoTo enditall Application.EnableEvents = False 'for a single cell............ If Target.Address = "$C$5" Then 'For a range 'If Not Application.Intersect(Range("A1:A20"), Target) Is Nothing Then 'for a column.............. 'If Target.Cells.Column = 3 Then ActiveSheet.Unprotect Password:="justme" If Target.Value < "" Then Target.Locked = True End If End If enditall: Application.EnableEvents = True ActiveSheet.Protect Password:="justme", DrawingObjects:=True, _ Contents:=True, Scenarios:=True End Sub This is sheet event code. Right-click on the sheet tab and "View Code" Copy/paste into that sheet module. NOTE: first select all cells and Format to "Unlocked" Gord Dibben MS Excel MVP On Tue, 1 May 2007 18:06:08 +0100, "Peter W Soady \(UK\)" wrote: Hi I have a bit of a quandary. I would like to know if it is possible to lock cells once the Enter / Return Key has been pressed or the cursor has been moved from the cell. I don't care if it is Macro or VBA as long as the cell can be locked. A simple example would be were you enter data in say cell C5, press Enter. I would like to lock that cell from being edited with the exception of Administrators. Many thanks in advance for any help I get Peter (UK)- Hide quoted text - - Show quoted text - Mr. Dibben, While that works, it still won't prevent anyone from just unprotecting the sheet. They don't have to be an admin, they just have to know how to view the code. The password is right there... Rob |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You now go into the VB Editor and place protection on the workbook code.
Then users cannot see the password or any code. Alt + F11 then CTRL + r Right-click on your workbook/project and Properties. Set "Lock for viewing" and give it a password..........not the same as the sheet password. Save and close to set the protection. When you re-open right-clicking on the sheet tab will pop up a password to view dialog. Gord On 1 May 2007 11:14:42 -0700, okrob wrote: Mr. Dibben, While that works, it still won't prevent anyone from just unprotecting the sheet. They don't have to be an admin, they just have to know how to view the code. The password is right there... Rob |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks guys
Will let you know how I get on. Appreciate the time. Again Many thanks "Gord Dibben" <gorddibbATshawDOTca wrote in message ... You now go into the VB Editor and place protection on the workbook code. Then users cannot see the password or any code. Alt + F11 then CTRL + r Right-click on your workbook/project and Properties. Set "Lock for viewing" and give it a password..........not the same as the sheet password. Save and close to set the protection. When you re-open right-clicking on the sheet tab will pop up a password to view dialog. Gord On 1 May 2007 11:14:42 -0700, okrob wrote: Mr. Dibben, While that works, it still won't prevent anyone from just unprotecting the sheet. They don't have to be an admin, they just have to know how to view the code. The password is right there... Rob |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Locking Cells when user inputs data | Excel Discussion (Misc queries) | |||
Locking in Formula cell to follow its cells that contain calc data | Excel Discussion (Misc queries) | |||
locking formula in cells in without locking whole sheet | Excel Discussion (Misc queries) | |||
locking data/cells so re-sorting a column doesn't re-position my d | Excel Discussion (Misc queries) | |||
Automatically locking cells following data entry | Excel Programming |