#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,101
Default lock used cells

I have a spreadsheet that I would like the cells to lock after a value has
been entered. Can I do this with a macro or in the sheet code?

Thanks

Mike
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4,624
Default lock used cells

One way:

Put this in the worksheet code module:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Const sPWORD As String = "drowssap"
Dim rArea As Range
Dim rCell As Range
Me.Unprotect Password:=sPWORD
For Each rArea In Target
For Each rCell In rArea
With rCell
.Locked = Not IsEmpty(.Value)
End With
Next rCell
Next rArea
Me.Protect Password:=sPWORD
End Sub

In article ,
MIke wrote:

I have a spreadsheet that I would like the cells to lock after a value has
been entered. Can I do this with a macro or in the sheet code?

Thanks

Mike

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,101
Default lock used cells

JE,

Thanks. It works great.

Mike

"JE McGimpsey" wrote:

One way:

Put this in the worksheet code module:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Const sPWORD As String = "drowssap"
Dim rArea As Range
Dim rCell As Range
Me.Unprotect Password:=sPWORD
For Each rArea In Target
For Each rCell In rArea
With rCell
.Locked = Not IsEmpty(.Value)
End With
Next rCell
Next rArea
Me.Protect Password:=sPWORD
End Sub

In article ,
MIke wrote:

I have a spreadsheet that I would like the cells to lock after a value has
been entered. Can I do this with a macro or in the sheet code?

Thanks

Mike


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,101
Default lock used cells

JE,

Wll these changes be applied to other worksheets if I need to add them?

Thanks,
Mike

"JE McGimpsey" wrote:

One way:

Put this in the worksheet code module:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Const sPWORD As String = "drowssap"
Dim rArea As Range
Dim rCell As Range
Me.Unprotect Password:=sPWORD
For Each rArea In Target
For Each rCell In rArea
With rCell
.Locked = Not IsEmpty(.Value)
End With
Next rCell
Next rArea
Me.Protect Password:=sPWORD
End Sub

In article ,
MIke wrote:

I have a spreadsheet that I would like the cells to lock after a value has
been entered. Can I do this with a macro or in the sheet code?

Thanks

Mike


  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4,624
Default lock used cells

No. If you want cells to be locked on *every* sheet in the workbook,
change the macro from the Worksheet_Change event to the
Workbook_SheetChange() event in the ThisWorkbook code module.


In article ,
MIke wrote:

Wll these changes be applied to other worksheets if I need to add them?



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default lock used cells

If you want the code to run on all sheets, current or added, change the event
type to

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)


Gord Dibben MS Excel MVP


On Fri, 19 Oct 2007 09:30:01 -0700, MIke wrote:

JE,

Wll these changes be applied to other worksheets if I need to add them?

Thanks,
Mike

"JE McGimpsey" wrote:

One way:

Put this in the worksheet code module:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Const sPWORD As String = "drowssap"
Dim rArea As Range
Dim rCell As Range
Me.Unprotect Password:=sPWORD
For Each rArea In Target
For Each rCell In rArea
With rCell
.Locked = Not IsEmpty(.Value)
End With
Next rCell
Next rArea
Me.Protect Password:=sPWORD
End Sub

In article ,
MIke wrote:

I have a spreadsheet that I would like the cells to lock after a value has
been entered. Can I do this with a macro or in the sheet code?

Thanks

Mike



  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default lock used cells

Missed one part.

Move the code to Thisworkbook module from sheet module.


Gord

On Fri, 19 Oct 2007 15:13:20 -0700, Gord Dibben <gorddibbATshawDOTca wrote:

If you want the code to run on all sheets, current or added, change the event
type to

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)


Gord Dibben MS Excel MVP


On Fri, 19 Oct 2007 09:30:01 -0700, MIke wrote:

JE,

Wll these changes be applied to other worksheets if I need to add them?

Thanks,
Mike

"JE McGimpsey" wrote:

One way:

Put this in the worksheet code module:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Const sPWORD As String = "drowssap"
Dim rArea As Range
Dim rCell As Range
Me.Unprotect Password:=sPWORD
For Each rArea In Target
For Each rCell In rArea
With rCell
.Locked = Not IsEmpty(.Value)
End With
Next rCell
Next rArea
Me.Protect Password:=sPWORD
End Sub

In article ,
MIke wrote:

I have a spreadsheet that I would like the cells to lock after a value has
been entered. Can I do this with a macro or in the sheet code?

Thanks

Mike


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 lock just some cells Cowtoon New Users to Excel 2 September 29th 06 11:21 PM
Lock all cells? JoeBed Excel Discussion (Misc queries) 8 June 1st 06 07:21 PM
How do I lock all cells in a given row together to one another? Michael Goldman Excel Discussion (Misc queries) 1 May 27th 06 08:17 AM
how can I lock certain cells? Linds Excel Discussion (Misc queries) 2 December 20th 05 10:46 PM
Lock Cells Diana Excel Discussion (Misc queries) 2 September 26th 05 07:27 PM


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