+ Reply to Thread
Results 1 to 14 of 14

VBA Code not unlocking specified cell...What am I doing wrong??????

Hybrid View

  1. #1
    Registered User
    Join Date
    11-13-2013
    Location
    Tempe, Arizona
    MS-Off Ver
    Excel 2010
    Posts
    6

    VBA Code not unlocking specified cell...What am I doing wrong??????

    Like most newbies I have a question that the rest can probably answer in their sleep but for the life of me I cannot get what I need to work!!!!

    I am trying to lock/protect Column "G" and make it accesible only if the contents in Column "F" (Rows 2 thru infinity) is either the letter "F" or "P" and to do nothing and continue to keep Column "G" locked/protected if the contents in Column "F" are "C" or nothing. I will eventually protect it with a password when I decide to allow other users to use the worksheet but for now it will be just me using it for the time being. This is what I have and please forgive me if I violate any rules as I am just trying to get past this difficult hurdle:

    Private Sub Worksheet_Change(ByVal Target As Range)
        ActiveSheet.Unprotect
        If Intersect(Target, Range("F2:F200")) Is Nothing Then Exit Sub
        If Target = "F" Or "P" Then
            Target.Offset(0, 7).Locked = False
        End If
        ActiveSheet.Protect
    End Sub
    Please help if you have the time because I am running out of it! A thousand apologies again for any violations or for coming off as a rookie, just need to get this taken care of so I can move forward in my life...lol
    Last edited by arlu1201; 11-13-2013 at 01:07 PM.

  2. #2
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: What am I doing wrong??????

    You have not stated the problem you have, but you may try this:
    Private Sub Worksheet_Change(ByVal Target As Range)
       Dim Cell                        As Range
       Me.Unprotect
       If Not Intersect(Target, Range("F2:F200")) Is Nothing Then
          Application.EnableEvents = False
          For Each Cell In Intersect(Target, Range("F2:F200")).Cells
             Select Case UCase$(Cell.Value)
                Case "F", "P"
                   Cell.Offset(0, 1).Locked = False
                Case Else
                   Cell.Offset(0, 1).Locked = True
             End Select
          Next Cell
          Application.EnableEvents = True
       End If
       Me.Protect
    End Sub
    Last edited by Izandol; 11-13-2013 at 11:57 AM. Reason: Correct misspelling

  3. #3
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: What am I doing wrong??????

    storresrl,

    Welcome to the forum. - 2 pointers

    1. I have added code tags to your post. As per forum rule 3, you need to use them whenever you put any code in your post. Please add them in future. In order to put code tags, either type [CODE] before your code and [/CODE] at the end of it, OR you can highlight your code and click the # icon at the top of your post window.

    2. Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution.

    Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.

    To change a Title on your post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  4. #4
    Registered User
    Join Date
    11-13-2013
    Location
    Tempe, Arizona
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: What am I doing wrong??????

    Thank you both for your quick responses.

    I have added the problem to my post title. Hope this is the information needed to proceed.

    Thank you arlu1201 for the advice although I do believe this site should make you acknowledge or accept the rules of this forum before proceeding. All it did was allow me to register and enter information not accept the rules or agree to abide by the rules of this forum.
    Last edited by storresrl; 11-13-2013 at 10:41 AM.

  5. #5
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: VBA Code not unlocking specified cell...What am I doing wrong??????

    What are F and P? the values?


    e/ Sorry arlu, I didn't see your post.
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  6. #6
    Registered User
    Join Date
    11-13-2013
    Location
    Tempe, Arizona
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: VBA Code not unlocking specified cell...What am I doing wrong??????

    Solus: I have corrected the code as required

    Yes Solus, F & P are the values. Basically Column F will be a status code column with only 3 options; F, P or C. If it is C or blank then I want to keep Coulmn G locked otherwise unlock Column G when F or P is entered into Column F and enter what I call a "Reason" code into Column G

    I tried Izandol's code and it does nothing. The worksheet still says Column G is locked and the worksheet still remains protected when data is entered into Column F

  7. #7
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: VBA Code not unlocking specified cell...What am I doing wrong??????

    Did you enter the code into the worksheet code module? It must be there and nowhere else.

  8. #8
    Registered User
    Join Date
    11-13-2013
    Location
    Tempe, Arizona
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: VBA Code not unlocking specified cell...What am I doing wrong??????

    Yes Izandol. I only have one worksheet (Sheet 1) under the folder Microsoft Excel Objects.

  9. #9
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: VBA Code not unlocking specified cell...What am I doing wrong??????

    Are you changing the cells in column F with manual input? Are you sure events are enabled?

  10. #10
    Registered User
    Join Date
    11-13-2013
    Location
    Tempe, Arizona
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: VBA Code not unlocking specified cell...What am I doing wrong??????

    Yes. It will be required for the user to input a code (F, P or C) into Column F and if it is either F or P then unlock Column G to allow input otherwise keep Column G locked

  11. #11
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: VBA Code not unlocking specified cell...What am I doing wrong??????

    I have seen that I mistyped a variable in the code - I have corrected it now.

  12. #12
    Registered User
    Join Date
    11-13-2013
    Location
    Tempe, Arizona
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: VBA Code not unlocking specified cell...What am I doing wrong??????

    It is fully functional and working great!

    Thanks for all of your help, especially you Izandol!

  13. #13
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: VBA Code not unlocking specified cell...What am I doing wrong??????

    If you are happy with the solution please mark the thread as [SOLVED] using the thread tools at the top.

  14. #14
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA Code not unlocking specified cell...What am I doing wrong??????

    There is a checkbox asking you if you agree to abide by the rules.

+ 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. Wrong coding or RANDBETWEEN is wrong?
    By zbor in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 07-31-2013, 10:01 AM
  2. Don't know what's wrong
    By eastray76 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-19-2008, 03:21 PM
  3. [SOLVED] What's that wrong?
    By Cactus in forum Excel General
    Replies: 1
    Last Post: 03-30-2006, 04:35 AM
  4. [SOLVED] What's wrong with this?
    By Damien McBain in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-07-2005, 10:05 AM
  5. [SOLVED] What am I doing wrong?
    By Jeff in forum Excel General
    Replies: 6
    Last Post: 03-05-2005, 11:07 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