+ Reply to Thread
Results 1 to 10 of 10

lock/unlock cell based on another cells input

  1. #1
    Forum Contributor
    Join Date
    01-05-2009
    Location
    South Dakota, USA
    MS-Off Ver
    2003, and 2007
    Posts
    150

    lock/unlock cell based on another cells input

    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.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: lock/unlock cell based on another cells input

    Make sure you set up the sheet with protection - unlock input cells, etc.
    Please Login or Register  to view this content.

    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

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: lock/unlock cell based on another cells input

    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)

  4. #4
    Forum Contributor
    Join Date
    01-05-2009
    Location
    South Dakota, USA
    MS-Off Ver
    2003, and 2007
    Posts
    150

    Re: lock/unlock cell based on another cells input

    Quote Originally Posted by royUK View Post
    Make sure you set up the sheet with protection - unlock input cells, etc.
    Please Login or Register  to view this content.

    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
    This comes up with an ambiguous name selected: worksheet_selectionchange

  5. #5
    Forum Contributor
    Join Date
    01-05-2009
    Location
    South Dakota, USA
    MS-Off Ver
    2003, and 2007
    Posts
    150

    Re: lock/unlock cell based on another cells input

    Quote Originally Posted by DonkeyOte View Post
    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)
    The entire sheet is protected and only unlocked cell can be edited

  6. #6
    Forum Contributor
    Join Date
    01-05-2009
    Location
    South Dakota, USA
    MS-Off Ver
    2003, and 2007
    Posts
    150

    Re: lock/unlock cell based on another cells input

    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
    Please Login or Register  to view this content.
    Last edited by royUK; 02-26-2009 at 03:08 AM.

  7. #7
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988

    Re: lock/unlock cell based on another cells input

    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 !!!

  8. #8
    Forum Contributor
    Join Date
    01-05-2009
    Location
    South Dakota, USA
    MS-Off Ver
    2003, and 2007
    Posts
    150

    Re: lock/unlock cell based on another cells input

    sorry about that I figured that out on my next post

    Thanks

  9. #9
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: lock/unlock cell based on another cells input

    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
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    08-21-2013
    Location
    St. Paul, MN
    MS-Off Ver
    Excel 2003
    Posts
    1

    Re: lock/unlock cell based on another cells input

    "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?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1