+ Reply to Thread
Results 1 to 18 of 18

lock cells based on another cell value inexcel

  1. #1
    Registered User
    Join Date
    03-06-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    95

    lock cells based on another cell value inexcel

    Hi,

    please help to write VBA code to lock cells based on the other cell value.

    In Sheet 1 from column A to F i have some data, based on the column F value i want to block the columns W,X,Y, means wherever the column F value is having "Died" I want to unlock the columns W,X,Y to enter some data, if it is not "Died" I want to lock columns W,X,Y and cursor has to move from column V to column Z

    Please help me

    Thanks & Regards

  2. #2
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: lock cells based on another cell value inexcel

    Hi
    something like this should do the job:
    Put this in the sheet module where your data are.

    Please Login or Register  to view this content.
    Note:
    1.The cells that will be editable should be unlocked in advance e.g. range A:F
    2.cells in W:Y should be Locked unlocked properly in advance, i.e. if you have Died in F2, then W2:Y2 should be set to unlocked
    3.After running the macro your sheet will be protected, without password and only cell that are unlocked will be editable and selectable.
    2. Prot
    If you are pleased with a member's answer then use the Star icon to rate it.

  3. #3
    Registered User
    Join Date
    03-06-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: lock cells based on another cell value inexcel

    Thank you for your reply,

    column A to Column F columns are not editable why because those columns are auto generated from other sheet and user is not allowed to change those values. Please help me to write a code for without changing the values in column A to F

    Please help me

    Thanks in advance

  4. #4
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: lock cells based on another cell value inexcel

    I don't understand your workflow. can you elaborated a little?
    which cells should be editable and which - not. how it should lock/unlock the cells?

  5. #5
    Registered User
    Join Date
    03-06-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: lock cells based on another cell value inexcel

    sorry for inconvenience,

    I will explain clearly, In Sheet1 from column A to F are having some data (this is auto generated by other sheet) and it is locked. Based on the available data in column A to F user have to enter some data in other columns (G to Z) which are empty. but I want to lock columns W,X,Y wherever Column F is having other than "Died".

    For example
    F2 is having "X" user can enter data in columns from G to Z except W,X,Y (When user entered data in to column V immediately cursor has to move from V to Z)

    F3 is having "Died" user can enter data in all columns from G to Z

    Thank you so much for your help

  6. #6
    Registered User
    Join Date
    03-06-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: lock cells based on another cell value inexcel

    Quote Originally Posted by chavanalini View Post
    sorry for inconvenience,

    I will explain clearly, In Sheet1 from column A to F are having some data (this is auto generated by other sheet) and it is locked. Based on the available data in column A to F user have to enter some data in other columns (G to Z) which are empty. but I want to lock columns W,X,Y wherever Column F is having other than "Died".

    For example
    F2 is having "X" user can enter data in columns from G to Z except W,X,Y (When user entered data in to column V immediately cursor has to move from V to Z)

    F3 is having "Died" user can enter data in all columns from G to Z

    Thank you so much for your help
    Please help me

  7. #7
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: lock cells based on another cell value inexcel

    try this

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    03-06-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: lock cells based on another cell value inexcel

    Thank you so much for your reply, but it is not working

    Please tell me where i have to copy this code and tell me which columns I have to lock and which columns I have to unlock before run this code

    Thank you

  9. #9
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: lock cells based on another cell value inexcel

    put it in a normal module.
    it doesn't matter which cells are locked or unlocked. I unlock all cells in columns G:Z, then I lock the cells W:Y for which"value in F column is not "Died".
    At the end user should be able to edit cells In G:V and Z for which you don't have Died and G:Z for these where F=Died

  10. #10
    Registered User
    Join Date
    03-06-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: lock cells based on another cell value inexcel

    Thank you,

    I inserted a new module and I pasted the code but its not working, I am attaching my excel file, please help me how to do this

    Yellow colour columns has to be locked when the F column is not have "Died"

    Thanks
    Attached Files Attached Files

  11. #11
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: lock cells based on another cell value inexcel

    I think now this should work
    Please Login or Register  to view this content.
    I assume for all cells Locked property is TRUE, which is the default value. The problem was due to the merged cells in row 1

  12. #12
    Registered User
    Join Date
    03-06-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: lock cells based on another cell value inexcel

    sorry for troubling you it is not working,

    If you dont mind can you put this code in to my excel file and see whether it is working or not, if it is working please forward the same file to me

    sorry for troubling you so much

    and thank you so much for you timely help

    thanks

  13. #13
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: lock cells based on another cell value inexcel

    here it is. run macro LockCells
    Attached Files Attached Files

  14. #14
    Registered User
    Join Date
    03-06-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: lock cells based on another cell value inexcel

    Thank you so much it is working, one small doubt whenever I will open excel file is it i have to run macro?

  15. #15
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: lock cells based on another cell value inexcel

    you should run macro after you add/update values in A:F

  16. #16
    Registered User
    Join Date
    03-06-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: lock cells based on another cell value inexcel

    Ok but it is little difficult to user to run macro every time is there any other way to do this

  17. #17
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: lock cells based on another cell value inexcel

    i give up. sorry...
    it's either user run macro after data are extracted from the DB, or like my first suggestion which you didn't like, if data on worksheet change.

  18. #18
    Registered User
    Join Date
    03-06-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: lock cells based on another cell value inexcel

    Thank you so much i will take your first suggestion only

+ 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 cell based on another cells input
    By 2funny4words in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-21-2013, 03:17 PM
  2. Conditionally lock multiple cells in a row based on one cell value.
    By DavidPAR in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-10-2012, 02:10 PM
  3. 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
  4. Lock cells within a row based on cell value
    By PY_ in forum Excel General
    Replies: 2
    Last Post: 11-14-2010, 12:40 AM
  5. Conditionally lock cells based on value in input cell
    By mbrady1973 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-09-2008, 06:54 PM

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