+ Reply to Thread
Results 1 to 16 of 16

Macro Code for cell locking

  1. #1
    Registered User
    Join Date
    10-28-2012
    Location
    Afghanistan, Kabul
    MS-Off Ver
    Office 2013
    Posts
    48

    Macro Code for cell locking

    I want know how can Lock a cell automatically after editing or writing in that cell. It means when i write anything in a specific cell after writing it become lock automatically with a specific Password that i give it and no one can edited twice without entering password. I mean that the specific cell must be unlocked for first time editing and become lock for second time and so on. Please send me A Macro or other to able I do this. Thanks

  2. #2
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Macro Code for cell locking

    This assumes that cell B9 starts out unlocked. Put this macro in the worksheet code area:

    Please Login or Register  to view this content.
    This is an Event Macro:


    Because it is worksheet code, it is very easy to install and automatic to use:
    1. right-click the tab name near the bottom of the Excel window
    2. select View Code - this brings up a VBE window
    3. paste the stuff in and close the VBE window
    If you have any concerns, first try it on a trial worksheet.

    If you save the workbook, the macro will be saved with it.


    To remove the macro:
    1. bring up the VBE windows as above
    2. clear the code out
    3. close the VBE window
    To learn more about macros in general, see:

    http://www.mvps.org/dmcritchie/excel/getstarted.htm

    To learn more about Event Macros (worksheet code), see:

    http://www.mvps.org/dmcritchie/excel/event.htm

    Macros must be enabled for this to work!
    Gary's Student

  3. #3
    Registered User
    Join Date
    10-28-2012
    Location
    Afghanistan, Kabul
    MS-Off Ver
    Office 2013
    Posts
    48

    Re: Macro Code for cell locking

    Hi dear my Friend!
    Your Macro code is the best but i want that when i type any thing in cell B9 just lock cell B9 and when i type any thing in cell B10 lock cell B10 not all sheet. Please help my dear brother.

  4. #4
    Registered User
    Join Date
    10-28-2012
    Location
    Afghanistan, Kabul
    MS-Off Ver
    Office 2013
    Posts
    48

    Re: Macro Code for cell locking

    Hi dear my Friend!
    Your Macro code is the best but i want that when i type any thing in cell B9 just lock cell B9 and when i type any thing in cell B10 lock cell B10 not all sheet. Please help my dear brother.

  5. #5
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Macro Code for cell locking

    Here is a different version. It will lock any cell after the cell has been filled:

    Please Login or Register  to view this content.
    You must erase the first version.

  6. #6
    Registered User
    Join Date
    10-28-2012
    Location
    Afghanistan, Kabul
    MS-Off Ver
    Office 2013
    Posts
    48

    Re: Macro Code for cell locking

    I am thinking that you don't receive my aim. I want that when any one write some thing in cell A1 just this cell must lock and after that when he write any thing in cell B6 just A1 and B6 must lock not whole sheet and so on please help me my dear.

  7. #7
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Macro Code for cell locking

    It is a matter of the order of things.


    1. start with all ( or most) cells unlocked
    2. enter the macro

    At this point you (or the user) can enter a value in any cell. Once you have entered the value, that single cell becomes locked, even though the worksheet is protected, the other cells are not yet locked and values may be entered into them.

  8. #8
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Macro Code for cell locking

    I have attached an example.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    10-28-2012
    Location
    Afghanistan, Kabul
    MS-Off Ver
    Office 2013
    Posts
    48

    Re: Macro Code for cell locking

    when i have many cell like for fees paid when i write paid in cell A4 just this well lock but when i write paid in A5 this is not lock. I want that this code select a range and after every typing it must update and lock the second cell too. thanks dear.

  10. #10
    Registered User
    Join Date
    10-28-2012
    Location
    Afghanistan, Kabul
    MS-Off Ver
    Office 2013
    Posts
    48

    Re: Macro Code for cell locking

    Thanks my problem was solved. So much thanks my real friend.

  11. #11
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Macro Code for cell locking

    If you any further help, update this post or open another.

  12. #12
    Registered User
    Join Date
    10-28-2012
    Location
    Afghanistan, Kabul
    MS-Off Ver
    Office 2013
    Posts
    48

    Re: Macro Code for cell locking

    Dear Jakobshavn Please can you Edit your Automatic Cell Locking Macro Code For a Specific Range I mean Edit this macro code to work or apply in a specific range like (B7:D9) please don't Forget me.

  13. #13
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Macro Code for cell locking

    Here it is
    Attached Files Attached Files

  14. #14
    Registered User
    Join Date
    10-28-2012
    Location
    Afghanistan, Kabul
    MS-Off Ver
    Office 2013
    Posts
    48

    Re: Macro Code for cell locking

    Thanks. Your Macro Code was Great. Please help in this tread too with your kindness : http://www.excelforum.com/excel-gene...html?p=3036420

  15. #15
    Registered User
    Join Date
    06-17-2013
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003
    Posts
    1

    Re: Macro Code for cell locking

    Quote Originally Posted by Jakobshavn View Post
    I have attached an example.
    How do I view this coding so that I Can use it for other excel

  16. #16
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Macro Code for cell locking

    Here is the code:

    Please Login or Register  to view this content.
    The instructions to view, install, and remove this type of code were given in my first post.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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