+ Reply to Thread
Results 1 to 7 of 7

VBA for Locking Column

  1. #1
    Forum Contributor wedzmer's Avatar
    Join Date
    06-13-2014
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    422

    VBA for Locking Column

    Hello excelites!!!

    I would like to ask if there is a macro code for locking a certain column, example, column D wherein all the formula entries for that column would not be clicked... I tried to lock using the properties but it distorts also the vba code I used.. So I would like to ask if there's a macro for locking columns...

    Im trying to lock columns B,C,D,E and H so that my colleagues will not be changing the formula I used on these cells on the said columns.

  2. #2
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: VBA for Locking Column

    without VBA

    excel 2007 => control => worksheet protect

    there you can add an password to project (some parts) of the workbook.
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: VBA for Locking Column

    You need to set the Locked property of cells. This will then take affect when you protect the sheet.

    If you have code manipulating locked cells you may need to remove and re-apply sheet protection in your code.
    Attached Files Attached Files
    Cheers
    Andy
    www.andypope.info

  4. #4
    Forum Contributor wedzmer's Avatar
    Join Date
    06-13-2014
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    422

    Re: VBA for Locking Column

    I know how to lock cells without macro... But when I do that on my macro-enabled worksheets, it distorts the running vba codes... That's where I'm having problems...

    This is why I was asking if it was possible to lock the whole columns using a VBA code.

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: VBA for Locking Column

    Without details we have no idea what you mean by "distorts the running vba codes"

    As I said if the sheet is protected you will need to unprotect it whilst the code in running and reapply it when finished.
    The macro recorder will provide code need.

  6. #6
    Forum Contributor wedzmer's Avatar
    Join Date
    06-13-2014
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    422

    Re: VBA for Locking Column

    Quote Originally Posted by Andy Pope View Post
    Without details we have no idea what you mean by "distorts the running vba codes"

    As I said if the sheet is protected you will need to unprotect it whilst the code in running and reapply it when finished.
    The macro recorder will provide code need.
    Hello Andy Pope!!!

    Thanks for your response... Here is my worksheet which I'm working on... As you can see, the worksheet already has VBA codes which is working properly as I wanted it to be.. However, every time I lock the columns J, O, P and Q via putting on a "protected worksheet" status... and then I use the "Hide" and/or the "Reset" Button I made for the VBA Codes, Excel prompts me with "Error 400"...

    Grading Sheet.xlsm

    I wanted these columns J, O, P and Q to be locked so that my other colleagues won't be able to accidentally change the values inside it.

    /The Macros have a password, it is "09193483966"/

    Thank you very much!

  7. #7
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: VBA for Locking Column

    toggle protection whilst running code.
    Please Login or Register  to view this content.
    You also need to format the cells so that the locked property is only set for cells in J,OPQ.
    Because you have merged cells you will need to select the cell range J14:134

    I have not used a password on sheet protection
    Attached Files Attached Files

  8. #8
    Forum Contributor wedzmer's Avatar
    Join Date
    06-13-2014
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    422

    Re: VBA for Locking Column

    Thank you very much!!!

    It worked perfectly!

+ 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. [SOLVED] TRULY locking a row or column
    By erisaaka in forum Excel General
    Replies: 4
    Last Post: 11-08-2012, 10:42 PM
  2. Column Locking
    By goodwinh in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-18-2011, 05:18 AM
  3. Locking column, but not row
    By danwhitehouse in forum Excel General
    Replies: 3
    Last Post: 05-19-2011, 08:38 AM
  4. locking column a only
    By zarathos in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-11-2008, 10:31 AM
  5. Locking column entries to an adjacent linked column
    By Steeljaw in forum Excel General
    Replies: 1
    Last Post: 01-23-2006, 06:50 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