Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9
Default lock a cell based on cell value

I am running Excel 2003 with a spreadsheet that has Activity in column A,
Status (Open or Closed) in column B, Days of Week (Sun thru Sat) in columns C
thru I. I am looking for a way to "lock" columns C thru I if column B is
"Closed" for each row of Activity in Column A

example:

Col A Col B Col C Col D Col E Col F
Activity 1 Closed lock lock lock lock
Activity 2 Open unlock unlock unlock unlock
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default lock a cell based on cell value

Assume that we begin with the worksheet unprotected and all cells unlocked.
Install this event macro in the worksheet code area:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim t As Range
Dim b As Range
Dim trow As Long
Set t = Target
Set b = Range("B:B")
If Intersect(t, b) Is Nothing Then Exit Sub
If t.Value < "Closed" Then Exit Sub
trow = t.Row
ActiveSheet.Unprotect
Range("C" & trow & ":I" & trow).Locked = True
ActiveSheet.Protect
End Sub


Because it is worksheet code, it is very easy to install and automatic to use:

1. right-click the tab name near the bottom of the Excel window
2. select View Code - this brings up a VBE window
3. paste the stuff in and close the VBE window

If you have any concerns, first try it on a trial worksheet.

If you save the workbook, the macro will be saved with it.


To remove the macro:

1. bring up the VBE windows as above
2. clear the code out
3. close the VBE window

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

To learn more about Event Macros (worksheet code), see:

http://www.mvps.org/dmcritchie/excel/event.htm

--
Gary''s Student - gsnu200821


"Texins Karate" wrote:

I am running Excel 2003 with a spreadsheet that has Activity in column A,
Status (Open or Closed) in column B, Days of Week (Sun thru Sat) in columns C
thru I. I am looking for a way to "lock" columns C thru I if column B is
"Closed" for each row of Activity in Column A

example:

Col A Col B Col C Col D Col E Col F
Activity 1 Closed lock lock lock lock
Activity 2 Open unlock unlock unlock unlock

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
lock cell based on a condition Amanda Excel Worksheet Functions 22 June 25th 07 07:53 PM
I have lock a wookbook but one cell does not want to lock it Mimi Excel Discussion (Misc queries) 2 January 21st 07 10:59 PM
I have lock a wookbook but one cell does not want to lock it Mimi Excel Discussion (Misc queries) 1 January 21st 07 09:44 AM
Lock data in a cell a specific cell based on selection on other ce CrimsonPlague29 Excel Worksheet Functions 0 May 10th 06 11:06 AM
How to lock a row in a spreadsheet based on the value in a cell Prasad Excel Worksheet Functions 3 December 16th 05 05:18 PM


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