VBA lock/unlock cells based on if statements

Catyana

New Member
Joined
Jun 2, 2017
Messages
2
Hello, I have been lurking here for a long time and have learned much from all of you. Thank you!!! I have something that I haven't been able to find an answer to, so I'm hoping one of you can help.

I have an estimate sheet where the mark up % fields ("G21,G26,H21,H26") are locked unless certain quote types are selected within the Quote Type drop down (cell D6 - Types: Change Estimate, Dealer, Non-Contract Estimate) and the VBA to lock and unlock it has worked great.

But I now need to add an additional scenario that unlocks these fields when the quote type = "Tender Estimate" AND the value of another field (L36) is greater than 24. Cell L36 is a formula that produces a value (percentage). This is what I tried:

Code:
Option Explicit




 Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim myPassword As String


    myPassword = "xxxxxx"
    Unprotect Password:=myPassword
        If Range("D6").Text = "Change Estimate" Or Range("D6").Text = "Dealer" Or _
        Range("D6").Text = "Non-Contract Estimate" Then
        
            Range("G21,G26,H21,H26").Locked = False
        
        ElseIf Range("D6").Text = "Tender Estimate" And Range("L36").Value >= 25 Then
        
            Range("G21,G26,H21,H26").Locked = False
            
        Else
            Range("G21,G26,H21,H26").Locked = True
            
        End If
        
        Protect Password:=myPassword
        
End Sub

The first 3 Quote types still work to unlock the mark up fields, but the new part is not. What am I doing wrong?

Thanks (very much!!) in advance.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Forum statistics

Threads
1,223,967
Messages
6,175,664
Members
452,666
Latest member
AllexDee

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top