+ Reply to Thread
Results 1 to 6 of 6

Macro to unlock and lock cells in Different columns based on another cell value

  1. #1
    Registered User
    Join Date
    09-03-2012
    Location
    Christchurch New Zealand
    MS-Off Ver
    Excel 2013
    Posts
    45

    Macro to unlock and lock cells in Different columns based on another cell value

    Hi All

    I need help with code to lock cell in the same row with "Environmental" or "Safety " value.
    Column H Contains either Environmental" or "Safety
    If Safety is selected I need the cell on the same row in column J to lock preventing someone from entering data
    If Environmental is selected I need the cell on the same row in column I to Lock
    I have written some code but it doesn't work it.
    Hoping someone can help and show me where I went wrong

    Please Login or Register  to view this content.

  2. #2
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: Macro to unlock and lock cells in Different columns based on another cell value

    this macro has to be at the sheet level not in a module.
    here is a macro that might help you. When you use the Worksheet.Change event, Target should be a single cell. If it is not, then you should exit the Sub.
    I programmed the unprotection of one column while protecting the other one. If you don't want this you may change the macro.


    Please Login or Register  to view this content.
    Pierre Leclerc
    _______________________________________________________

    If you like the help you got,
    Click on the STAR "Add reputation" icon at the bottom.

  3. #3
    Registered User
    Join Date
    09-03-2012
    Location
    Christchurch New Zealand
    MS-Off Ver
    Excel 2013
    Posts
    45

    Re: Macro to unlock and lock cells in Different columns based on another cell value

    Hi p24leclerc
    Thank you very much for your help
    It worked a treat
    One last question I am trying to get the code to do 3 different things and I am getting the error Compile error no next without for,
    I have looked and cannot find where I have gone wrong
    See code
    Please Login or Register  to view this content.
    Your help is much appreciated

  4. #4
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: Macro to unlock and lock cells in Different columns based on another cell value

    See the modified macro and the comments below:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    09-03-2012
    Location
    Christchurch New Zealand
    MS-Off Ver
    Excel 2013
    Posts
    45

    Re: Macro to unlock and lock cells in Different columns based on another cell value

    Sorry to be a pain
    I have changed the Code as you have advised.
    But it now does not seem to be working correctly
    It does not protect the column required and causes all macros on sheet to stop running (without error)
    I have attached the Worksheet and I am hoping you can have a quick look to see why it is not working
    Reports.xlsm
    None of the Worksheet_Change(ByVal Target As Range) actions are preformed
    Letter does not become capital on K column
    Time stamp does not appear when "Completed"
    Collumns stop hiding when target is selected
    Last edited by bouncingbudha; 04-07-2015 at 08:58 PM.

  6. #6
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: Macro to unlock and lock cells in Different columns based on another cell value

    Attached workbook should now work.
    The issue came from the fact that the EnableEvents=True was being bypassed by an IF statement in your code.
    I don't understand all you want to do with this file but there are lots of macros
    that are doing the same things.
    As long as it works for you.
    Regards
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Lock/Unlock cells based on value in another cell
    By 13gentj in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-15-2014, 11:00 PM
  2. Lock/unlock specific cells in a row based on another cell content of the same row
    By st_rod000 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-10-2014, 02:58 AM
  3. lock/unlock cell based on another cells input
    By 2funny4words in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-21-2013, 03:17 PM
  4. Lock and unlock a cell or two cells based on a value of another cell
    By Rocky2013 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-23-2013, 07:34 PM
  5. How to lock and unlock a range of cells based on certain cell's value?
    By potato in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 01-25-2012, 04:34 AM

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