• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Unlock specific numbers of cells based on another cell value - VBA

A11 Mighty

Member
Hello -
I ve searched and didn't come across a solution that will help with my need. Looking for some assistance with my request:

Request #1
Need to unlock 1 specific cell in a row based on a specific value selected through a dropdown in the same row:
If B12 = OPEN, Unlock F12
NOTE: If the value of B12 is different than "Open" F12 should be locked
The code need to repeat for each row: If A13 = Open, F13.

Request #2
Need to unlock specific cells in a row based on a specific value selected in the same row, and if it's not too match asking change the color of the cell from current color to something that will indicate they are active or unlocked.
If F12 = 1, Unlock G12
If F12 = 2, Unlock both G12 & H12
If F12 = 3, Unlock G12 & H12 & I12
If F12 = 4, Unlock G12 & H12 & I12 & J12
If F12 = 5, Unlock G12 & H12 & I12 & J12 & K12
If F12 = Max, Unlock G12 & H12 & I12 & J12 & K12 & L12
The code need to repeat for each row: If F13= 1 then 2 .....

I've attached a sample sheet with current project layout I am working on.

Any help will be much appreciated.

Thank you,

A11 Mighty
 

Attachments

  • Chand, Lock - Unlock.xlsm
    28.3 KB · Views: 3
Hello @vletm apologies for the inconvenience with the file format.

The code provided works perfectly with the exception of the "MAX" option in cell F12
If F12 = Max, Unlock G12 & H12 & I12 & J12 & K12 & L12.

When I enter MAX manually I receive the following error
78973

Also, I've noticed that my command buttons "Add lines" & "Delete Line" no longer work. Is that because of the file format?

Thank you,
A11 Mighty
 
A11 Mighty
The fileformat was okay - ActiveX-components.
Case Max ... someone else than me has done some settings that it needs whole numbers as in Your snapshot.
Your command buttons - maybe those were ActiveX-components, which My Excel handle like pictures.
You could try connect those to Your codes.
... and another reason could be ... which options of Protect-sheet, those Your codes needs?
As You noticed, I used UserInterfaceOnly-feature, then Protect-settings can do once.
 
Yes, you are absolutely correct. I removed the Data Validation and that seemed to work.
The Command button codes are my attempt at creating something that works for my need. I really don't need the
ActiveSheet.Protect within the Command Buttons; just didn't feel comfortable with the limited knowledge I have make more adjustment.
Appreciate all your help and support.
A11 Mighty
 
See attached which has a
Private Sub Worksheet_Change(ByVal Target As Range)
macro in it which also has a few comments.
 

Attachments

  • Chandoo48064Chand, Lock - Unlock.xlsm
    34.1 KB · Views: 5
Hello @p45cal Much appreciated.
I really like the color and comments you added. Is there a way to have cell F12 change color as well when OPEN is selected in A12?
The code need to repeat itself for each row.

Thank you,
 
Change:
Code:
  For Each cll In rngBColmChange.Cells
    cll.Offset(, 4).Locked = cll.Value <> "OPEN"    'case sensitive
  Next cll
to:
Code:
  For Each cll In rngBColmChange.Cells
    With cll.Offset(, 4)
      .Locked = cll.Value <> "OPEN"    'case sensitive
      If cll.Value = "OPEN" Then .Interior.Color = 11854022 Else .Interior.Color = 14277081
    End With
  Next cll
 
Back
Top