Marco that will run if the condition met 2

H

Harn88

Hi

I need some help with this please. I want to create a Marco that will run if
the condition met.

My situation is the worksheet is already protected by my password (for
example my password is “Luckyâ€) however what I want is that if Cell A1 equal
to “Yes†then Cell B1 will be unprotected only. The other Cell in the
worksheet will remain protected and if it is equal to “No†then the cell will
remain protected. So after the Marco, the Cell B1,B2,B3,B4,B6,B9 will be
unprotected only.

--------------A-----------B
1-----------yes---------100
2-----------yes---------656
3-----------yes---------556
4-----------yes---------964
5-----------no-----------32
6-----------yes---------496
7-----------no---------656464
8-----------no---------656
9-----------yes---------656

Just in case that the example did not come out too great, number 1 to 9 is
row numbers and A&B
is column. So "yes" will be in Row 1 Column A and the amount will be in Row
1 column B

Thank you very much for your help!!!

Best regards,

Harn
 
M

Mike H

Hi,

Right click your sheet tab, view code and paste this in and run it.

Sub sonic()
Dim MyRange As Range
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Set MyRange = Range("A1:A" & lastrow)
ActiveSheet.Unprotect Password:="Lucky"
For Each c In MyRange
If UCase(c.Value) = "YES" Then
c.Offset(, 1).Locked = False
End If
Next
ActiveSheet.Protect Password:="Lucky"
End Sub

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top