basically, I want cell g12 to be locked unless cell h7 is Grass Fire or Timber Fire (H7 is a drop down validated cell)
basically, I want cell g12 to be locked unless cell h7 is Grass Fire or Timber Fire (H7 is a drop down validated cell)
Last edited by 2funny4words; 03-03-2009 at 05:32 PM.
Make sure you set up the sheet with protection - unlock input cells, etc.
![]()
Option Explicit Private Sub Worksheet_SelectionChange(ByVal Target As Range) Const PW As String = "secret" If Target.Address = "$G$12" Then Select Case Cells(7, 8).Value Case "Grass Fire", "Timber Fire" ActiveSheet.Unprotect PW Target.Locked = False ActiveSheet.Protect PW End Select End If End Sub
Copy the code
Select the worksheet in which you the want the code to run
Right click on the sheet tab and choose View Code, to open the Visual Basic Editor.
Where the cursor is flashing, choose Edit | Paste
Hope that helps.
RoyUK
--------
For Excel Tips & Solutions, free examples and tutorials why not check out my web site
Free DataBaseForm example
You could theoretically use Data Validation on G12 also, no ?
G12: Validation: Custom: =OR(H7="Grass Fire",H7="Timber Fire")
However this won't physically clear contents of G12 as and when H7 is altered to something other than the 2 choices mentioned if that is your intention
In terms of using VBA you can use a Worksheet_Change event to physically lock/unlock the cell but this would require the entire sheet be protected - is that what you're looking to do ? It is unclear (to me at least)
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
I tried DonkeyOte's idea and it worked but not quite like I wanted it to.
When I tried royUK's code I come up with a compile error: Ambiguous name detected: Worksheet_SelectionChange
here is the code that I have
![]()
[Private Sub Worksheet_SelectionChange(ByVal Target As Range) Const PW As String = "secret" If Target.Address = "$G$12" Then Select Case Cells(7, 8).Value Case "Grass Fire", "Timber Fire" ActiveSheet.Unprotect PW Target.Locked = False ActiveSheet.Protect PW End Select End If End Sub]
Last edited by royUK; 02-26-2009 at 03:08 AM.
2funny4words,
Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
VBA Noob
_________________________________________
![]()
![]()
Credo Elvem ipsum etian vivere
_________________________________________
A message for cross posters
Please remember to wrap code.
Forum Rules
Please add to your signature if you found this link helpful. Excel links !!!
sorry about that I figured that out on my next post
Thanks
The ambiguous name error is caused bevause you have two procedures with the same name, the SelectionChange event might already be in use.
Use this, it will run whenever G12 is changed
![]()
[Private Sub Worksheet_Change(ByVal Target As Range) Const PW As String = "secret" If Target.Address = "$G$12" Then Select Case Cells(7, 8).Value Case "Grass Fire", "Timber Fire" ActiveSheet.Unprotect PW Target.Locked = False ActiveSheet.Protect PW End Select End If End Sub]
"The ambiguous name error is caused bevause you have two procedures with the same name, the SelectionChange event might already be in use."
Is there possibly another procedure to use if SelectionChange and Change are in use?
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks