Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Locking Data Cells

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 142
Default Locking Data Cells

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Locking Data Cells

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 142
Default Locking Data Cells

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Locking Data Cells

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Locking Data Cells

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
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
Locking Cells when user inputs data NervousFred Excel Discussion (Misc queries) 0 August 1st 08 09:34 PM
Locking in Formula cell to follow its cells that contain calc data Jason52 Excel Discussion (Misc queries) 1 April 13th 07 07:08 PM
locking formula in cells in without locking whole sheet SuziQ Excel Discussion (Misc queries) 1 July 21st 06 03:58 PM
locking data/cells so re-sorting a column doesn't re-position my d mtn_leisure Excel Discussion (Misc queries) 3 August 17th 05 10:32 PM
Automatically locking cells following data entry Brian Larkin Excel Programming 4 September 25th 03 10:31 AM


All times are GMT +1. The time now is 12:31 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"