Can someone please help me out. I've been reading about VBA scripting that allows for the unlocking of cells based on another cell's value, but I just can't seem to make it work with my spreadsheet or even with a blank spreadsheet.
Here is what I would like to do:
I have cell A1: A5 with a validation values of the following (a list) "Yes", "No", and "Select".
If A2 = "Yes" – I would like to see cell B2 = unlocked;
If A2 = "No" – I would like to see cell B2 = unlocked; and
If A2 = "Select" – I would like to see cell B2 = locked.
Any input is greatly appreciated.
Here is the code:
If LCase(Range("A2:A10")) = "Yes" Then
Range("B2:B10").Locked = False
ElseIf LCase(Range("A2:A10")) = "No" Then
Range("B2:B10").Locked = False
ElseIf LCase(Range("A1:A10")) = "Select" Then
Range("B2:B10").Locked = True
End If
End Sub
Ps. I read a few comments on Stackoverflow, but the info does not seem to work.
https://www.teachexcel.com/excel-help/excel-how-to.php?i=302178
Thank you all in advance.
Loop through the cells in column A and perform an action on the cells in column B through an offset.
dim rng as range
with worksheets("sheet1")
for each rng in .range("a2:a10")
select case lcase(rng.value2)
case "yes", "no"
rng.offset(0, 1).locked = false
case "select"
rng.offset(0, 1).locked = true
case else
'do nothing if not yes, no or select
end select
next rng
end with
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.