+ Reply to Thread
Results 1 to 16 of 16

Unlocking Cells if condition met

  1. #1
    Registered User
    Join Date
    01-30-2015
    Location
    Guwahati
    MS-Off Ver
    2007
    Posts
    11

    Unlocking Cells if condition met

    Please see the attached file.

    Requirements
    If Cell A2 has "Yes" then unlock Cells B2:B5

    Note:
    1) All other locked cells must be protected at all times.
    2) The Macro should not ask the user to enter password, but the macro should have the password inbuilt itself.
    3) If after entering data in B2:B5 the user removes "Yes" from A2, then Cells B2:B5 should become blank again & Locked.

    Looking for urgent help.
    Attached Files Attached Files

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: Unlocking Cells if condition met

    Start by locking all the cells in your worksheet and then unlock cell A2. Protect the worksheet with a password of your choosing. Copy and paste this macro into the worksheet code module. Do the following: right click the tab for your sheet and click 'View Code'. Paste the macro into the empty code window that opens up. Change "mypassword" (two occurrences) in the code to the chosen password. Close the code window to return to your sheet.
    Please Login or Register  to view this content.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Registered User
    Join Date
    01-30-2015
    Location
    Guwahati
    MS-Off Ver
    2007
    Posts
    11

    Re: Unlocking Cells if condition met

    Thank you very much.
    It works fantastically well.

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: Unlocking Cells if condition met

    My pleasure.

  5. #5
    Registered User
    Join Date
    01-30-2015
    Location
    Guwahati
    MS-Off Ver
    2007
    Posts
    11

    Re: Unlocking Cells if condition met

    In continuation with my above mentioned query, I am facing this problem now

    I want to set more than 1 conditions in one sheet, then how to change the macro accordingly.

    for example

    If A2 = "Yes" then B2:F2 unlocked
    If A3 = "Yes" then B3:F3 unlocked

    clear contents if condition not met and sheet protected again.

  6. #6
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: Unlocking Cells if condition met

    Try:
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    01-30-2015
    Location
    Guwahati
    MS-Off Ver
    2007
    Posts
    11

    Re: Unlocking Cells if condition met

    Please find attached the Exact Sample excel file I am working on.

    I am quite dumb at VBA and am Sorry for troubling you again

    Requirement 1

    If D4 = "A" then unlock G4:H4 & M4 with my password
    If D4 = "Select" or "" or "I" then clear contents & lock G4:H4 & M4 with my password

    Requirement 2

    If B12="Y" then unlock C12:H12 & J12:M12 with my password
    If B12= "" then lock C12:H12 & J12:M12 & Clear Contents with my password
    If B13="Y" then unlock C13:H13 & J13:M13
    If B13= "" then lock C13:H13 & J13:M13 & Clear Contents
    the same upto B30

    Requirement 3

    If M32 > 0 the unlock D35 & F35 with my password
    If M32 = 0 or "" then lock D35 & F35 & clear contents with my password

    Apart from this at all times the protectec cells must be locked

    I know its too specific but I need urgent help ...Please Help...
    Attached Files Attached Files

  8. #8
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: Unlocking Cells if condition met

    Try the attached file. I've changed the data validation in B12:B30 to include a blank space. I've also had to unmerge G4:J4 as the merged cells were causing problems. Hopefully, this works for you.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    01-30-2015
    Location
    Guwahati
    MS-Off Ver
    2007
    Posts
    11

    Re: Unlocking Cells if condition met

    Superb,
    Thanks for your valuable time
    I managed to work it with the merged cell by changing a fe things in the code as under

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("D4, B12:B30, M32")) Is Nothing Then Exit Sub
    ActiveSheet.Unprotect Password:="mypassword"
    Dim x As Long
    If Target = "A" And Target.Column = 4 Then
    Range("G4:J4").Locked = False
    Range("M4").Locked = False
    ElseIf Target = "Select" Or Target = "" Or Target = "I" And Target.Column = 4 Then
    Range("G4:J4").ClearContents
    Range("M4").ClearContents
    Range("G4:J4").Locked = True
    Range("m4").Locked = True
    End If

    Thank you so much for the help. You made my day.

    Will trouble you if more help is required.

  10. #10
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: Unlocking Cells if condition met

    My pleasure.

  11. #11
    Registered User
    Join Date
    01-30-2015
    Location
    Guwahati
    MS-Off Ver
    2007
    Posts
    11

    Re: Unlocking Cells if condition met

    Dear Mumps 1,
    Please see the file attached.

    I am facing the followin problems

    1)When * is removed from any cell of B11:B30 an error comes.

    2) I have changed the codes you gave me to meet my modified requirement due to which the above problem came and the file has become very very very slow.

    3)New Requirement: There is a drop down in H11:H30 dependant on G11:G30 via INDIRECT formula.
    What is happening is that If a value in G11 is selected and a correponding value in is selected there is no problem. But when G11 is changed the value in Hll remains which is not corresponding to the value in G11 causing error. Is it possible that the value in H11 turns to blank or refreshes upon every change in G11 and so on.

    Can all this be done without making the file slow.

    Please Please Please help.
    Attached Files Attached Files

  12. #12
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: Unlocking Cells if condition met

    I couldn't reproduce the error when * is removed from any cell of B11:B30. It worked properly for me. I'm afraid that I couldn't come up with a solution to your other issue.

  13. #13
    Registered User
    Join Date
    01-30-2015
    Location
    Guwahati
    MS-Off Ver
    2007
    Posts
    11

    Re: Unlocking Cells if condition met

    When I delete *
    a message box comes saying
    Run-time error '13'
    Type mismatch

    and when I hit debug
    The following portion becomes yellow
    If Target = "Advance" And Target.Column = 4 Then

  14. #14
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: Unlocking Cells if condition met

    I'm afraid that I'm not getting any error when I try it. It works properly.

  15. #15
    Registered User
    Join Date
    01-30-2015
    Location
    Guwahati
    MS-Off Ver
    2007
    Posts
    11

    Re: Unlocking Cells if condition met

    Dear Mumps 1,

    I had attached the wrong file earlier.

    Please see the file attached with the message and help where I am going wrong.

    Please help.
    Attached Files Attached Files

  16. #16
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: Unlocking Cells if condition met

    I've been looking at your file and I can't figure out what the problem could be. Could I suggest that you start a new thread posting your file and a detailed explanation of what you want to do. I'm sure that there is some forum member who will have a solution for you. Sorry.

+ 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. Unlocking Chart Axis Title under locked sheet without unlocking the sheet
    By dalelengle in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-16-2012, 08:59 PM
  2. Locking and unlocking of cells
    By srinivassurapareddi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-12-2012, 02:19 AM
  3. Locking and Unlocking Cells
    By vikas.bhandari in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-22-2010, 10:27 AM
  4. Code not unlocking cells as it should be
    By nhrav in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-23-2008, 02:21 PM
  5. conditional unlocking of cells
    By hiryuu in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-19-2005, 07:44 AM

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