简体   繁体   English

根据另一个单元格的值锁定和解锁单元格(excel 2013)

[英]lock and unlock cells based on another cell's value (excel 2013)

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. 我一直在阅读有关VBA脚本的知识,该脚本允许根据另一个单元格的值来解锁单元格,但是我似乎无法使其与我的电子表格甚至是空白电子表格一起使用。

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". 我的单元格A1:A5的验证值如下(“列表”)“是”,“否”和“选择”。

If A2 = "Yes" – I would like to see cell B2 = unlocked; 如果A2 =“是” –我希望看到单元格B2 =解锁;

If A2 = "No" – I would like to see cell B2 = unlocked; 如果A2 =“否” –我想看到单元格B2 =解锁; and

If A2 = "Select" – I would like to see cell B2 = locked. 如果A2 =“选择” –我希望看到单元格B2 =锁定。

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. 我读了一些关于Stackoverflow的评论,但该信息似乎不起作用。

https://www.teachexcel.com/excel-help/excel-how-to.php?i=302178 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. 循环浏览A列中的单元格,并通过偏移量对B列中的单元格执行操作。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM