Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default lock / unlock dynamically

Hi guys,

Can I lock or unlock a column, row or cell(s) dynamically depending on the
content of another cell? I have a drop down list where a user chooses
country, if it is the US then i want them to be able to imput address,
otherwise I want the adress columns to be locked.
--

Thanks in advance,
Matt

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 618
Default lock / unlock dynamically

Hi Matt

this code will unlock the cell in column E of the same row that "US" is
input into in column A ... then if another change is made anywhere on the
sheet the whole of column E will be locked again ...

--------
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Column = 1 And Target.Value = "US" Then
ActiveSheet.Unprotect ("pwd")
Target.Offset(0, 4).Locked = False
ElseIf Target.Column < 1 Then
ActiveSheet.Unprotect ("pwd")
Columns("E:E").Locked = True
ActiveSheet.Protect ("pwd")
End If

End Sub
--

to use the code, right mouse click on the sheet tab against which you want
to run the code and choose view code - the VBE window will be displayed.
Copy & paste the code above into the right hand side of the screen ...
change the 1 to the appropriate number of the column (A = 1, B= 2 etc) where
the countries are listed
change "E:E" to the column where the addresses are entered
also change Offset(0,4) to match the above to settings ... Offset(0,4) means
that the address cell is on the same row but 4 columns to the right of the
country cell.
change
pwd
to the actual password you want to protect your sheet with

--
Cheers
JulieD
check out www.hcts.net.au/tipsandtricks.htm
....well i'm working on it anyway
"MaBell" wrote in message
...
Hi guys,

Can I lock or unlock a column, row or cell(s) dynamically depending on the
content of another cell? I have a drop down list where a user chooses
country, if it is the US then i want them to be able to imput address,
otherwise I want the adress columns to be locked.
--

Thanks in advance,
Matt



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default lock / unlock dynamically

Great ! Thanks!

"JulieD" wrote:

Hi Matt

this code will unlock the cell in column E of the same row that "US" is
input into in column A ... then if another change is made anywhere on the
sheet the whole of column E will be locked again ...

--------
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Column = 1 And Target.Value = "US" Then
ActiveSheet.Unprotect ("pwd")
Target.Offset(0, 4).Locked = False
ElseIf Target.Column < 1 Then
ActiveSheet.Unprotect ("pwd")
Columns("E:E").Locked = True
ActiveSheet.Protect ("pwd")
End If

End Sub
--

to use the code, right mouse click on the sheet tab against which you want
to run the code and choose view code - the VBE window will be displayed.
Copy & paste the code above into the right hand side of the screen ...
change the 1 to the appropriate number of the column (A = 1, B= 2 etc) where
the countries are listed
change "E:E" to the column where the addresses are entered
also change Offset(0,4) to match the above to settings ... Offset(0,4) means
that the address cell is on the same row but 4 columns to the right of the
country cell.
change
pwd
to the actual password you want to protect your sheet with

--
Cheers
JulieD
check out www.hcts.net.au/tipsandtricks.htm
....well i'm working on it anyway
"MaBell" wrote in message
...
Hi guys,

Can I lock or unlock a column, row or cell(s) dynamically depending on the
content of another cell? I have a drop down list where a user chooses
country, if it is the US then i want them to be able to imput address,
otherwise I want the adress columns to be locked.
--

Thanks in advance,
Matt




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 618
Default lock / unlock dynamically

you're welcome
--
Cheers
JulieD

"MaBell" wrote in message
...
Great ! Thanks!

"JulieD" wrote:

Hi Matt

this code will unlock the cell in column E of the same row that "US" is
input into in column A ... then if another change is made anywhere on the
sheet the whole of column E will be locked again ...

--------
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Column = 1 And Target.Value = "US" Then
ActiveSheet.Unprotect ("pwd")
Target.Offset(0, 4).Locked = False
ElseIf Target.Column < 1 Then
ActiveSheet.Unprotect ("pwd")
Columns("E:E").Locked = True
ActiveSheet.Protect ("pwd")
End If

End Sub
--

to use the code, right mouse click on the sheet tab against which you
want
to run the code and choose view code - the VBE window will be displayed.
Copy & paste the code above into the right hand side of the screen ...
change the 1 to the appropriate number of the column (A = 1, B= 2 etc)
where
the countries are listed
change "E:E" to the column where the addresses are entered
also change Offset(0,4) to match the above to settings ... Offset(0,4)
means
that the address cell is on the same row but 4 columns to the right of
the
country cell.
change
pwd
to the actual password you want to protect your sheet with

--
Cheers
JulieD
check out www.hcts.net.au/tipsandtricks.htm
....well i'm working on it anyway
"MaBell" wrote in message
...
Hi guys,

Can I lock or unlock a column, row or cell(s) dynamically depending on
the
content of another cell? I have a drop down list where a user chooses
country, if it is the US then i want them to be able to imput address,
otherwise I want the adress columns to be locked.
--

Thanks in advance,
Matt






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default lock / unlock dynamically

OK, what happens if the user wrongly enters "US" in the Country column, then
enters the address, then realizes that they meant to enter "UK" for the
country? The address that they entered is now locked into the Address column
on that row, and can only be changed by temporarily changing the Country
back to "US", then back to "UK" again!
--
Regards,
Bill


"MaBell" wrote in message
...
Hi guys,

Can I lock or unlock a column, row or cell(s) dynamically depending on the
content of another cell? I have a drop down list where a user chooses
country, if it is the US then i want them to be able to imput address,
otherwise I want the adress columns to be locked.
--

Thanks in advance,
Matt





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/Unlock cells BFife Excel Worksheet Functions 2 October 25th 06 03:20 PM
unlock and lock VBAProject Lenny_821[_4_] Excel Programming 0 November 6th 04 11:48 AM
unlock and lock VBAProject Lenny_821[_3_] Excel Programming 1 November 5th 04 11:36 PM
unlock and lock VBAProject Lenny_821[_2_] Excel Programming 2 November 5th 04 12:25 PM
Lock/Unlock problem Jim[_34_] Excel Programming 3 January 17th 04 05:36 PM


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