+ Reply to Thread
Results 1 to 4 of 4

Conditional Range Lock in Vba not working

  1. #1
    Registered User
    Join Date
    08-02-2013
    Location
    Panama
    MS-Off Ver
    Excel 2010
    Posts
    2

    Conditional Range Lock in Vba not working

    Hello All, I have this code for conditional locking for a specific range and its not working

    Please Login or Register  to view this content.

    Please tell me if I am getting something wrong pls.

    Thanks in advance
    Last edited by sori11; 08-02-2013 at 05:07 PM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,532

    Re: Conditional Range Lock in Vba not working

    Welcome to the Forum sori11!

    First, I'll be gentle since it's your first post but there is a rule requiring CODE tags around code. Please review the rules--there aren't that many and they're all there for good reasons. (See below.)

    Second, what do you mean by "not working"? Do you get an error? Do the cells not get locked? How are you testing it? It would be ideal if you could attach a copy of your workbook so we can test it too.

    Just to be really, really clear, I am assuming that the worksheet being changed by the user is the same one with the cells you are locking. If that is not right, then stop right here and provide more explanation about what worksheets you have and where this code is and what you are trying to do.

    You don't say where this code is located but because it's a Worksheet_Change sub I assume it's in a worksheet module. However you are unprotecting ActiveSheet. Even though ActiveSheet is almost certain to be the worksheet containing this code (because a sheet has to be active for the user to change it), it might be better to simply use

    Please Login or Register  to view this content.
    That will unprotect the sheet that has just been changed, and whose cells you are locking. I don't think that's your problem, but try it anyway.



    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here
    Last edited by 6StringJazzer; 08-02-2013 at 04:29 PM. Reason: error in code, removed ActiveSheet. since that was the whole point
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    08-02-2013
    Location
    Panama
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Conditional Range Lock in Vba not working

    Hi 6StringJazzer,

    Thanks for the advice about posting, the code is not locking any cell specified. I would like to do this on specified worksheets and I need to get the cells locked according to the If condition value.

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,532

    Re: Conditional Range Lock in Vba not working

    I should have realized this right away but missed it; every If statement you have needs an End If. Your code does not compile. You will get a pop-up window showing you a compile error any time that the code tries to run. You haven't mentioned anything about seeing that, which leads me think that your code is in the wrong place and never even tries to run.

    As I suggested in my last post, I need more information about what module this code is in, what sheet you are expecting the user to change, and what sheet you are trying to change locked cells on.

    It would be simpler if you could attach your workbook.

+ 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 Conditional Formating
    By tahoejohno in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-29-2013, 12:13 AM
  2. [SOLVED] VBA code stops working when I lock the workbook for use
    By Sleepyshy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-04-2013, 02:55 PM
  3. Conditional Formatting - Grey Out and Lock A range based on a cell value in that range
    By Excelgnome in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-14-2012, 07:31 PM
  4. Conditional cell lock
    By coolanks in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 05-30-2008, 09:57 AM
  5. Lock range of cells dependant on date range
    By stir-crazy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-18-2008, 09:40 PM

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