简体   繁体   English

Excel VBA 根据整个工作表中的多项选择更改单元格值

[英]Excel VBA to change a cell value depending on multiple selection throughout the sheet

I have a cell (C25) at the bottom of a sheet that I want to either display "Yes" or "No" to the question "Requires Approval?"我在工作表底部有一个单元格 (C25),我想对问题“需要批准?”显示“是”或“否”。 I suppose No would be the default.我想 No 将是默认值。

Basically users are going to answer a series of questions using dropdowns throughout the form and depending on these selections it will tell them whether or not they require approval.基本上,用户将在整个表单中使用下拉菜单来回答一系列问题,并且根据这些选择,它会告诉他们是否需要批准。 The triggers are certain choices from 5 dropdown lists.触发器是 5 个下拉列表中的某些选项。 Precisely, 2 options from dropdown 1 (C4) trigger a Yes, the other 10 choices do not (No).准确地说,下拉列表 1 (C4) 中的 2 个选项会触发是,其他 10 个选项不会(否)。 1 option from dropdown 2 (C11) triggers a yes, the other do not and so on.下拉列表 2 (C11) 中的 1 个选项触发是,另一个不触发,依此类推。

Additionally, if the user makes any selection that triggers a Yes, it must stay as a Yes.此外,如果用户做出任何触发 Yes 的选择,它必须保持为 Yes。 For example if they answer one dropdown that triggers a Yes and then answer another that does not, it should not set it to No, but if no value that triggers a Yes is selected anymore (for example, they change their mind and change the first dropdown selection), it should set it to No.例如,如果他们回答一个触发 Yes 的下拉列表,然后回答另一个不触发的下拉列表,则不应将其设置为 No,但如果不再选择触发 Yes 的值(例如,他们改变主意并更改第一个下拉选择),应将其设置为否。

I have no idea how to go about writing the code for this.我不知道如何为此编写代码。 I'm using 64-bit Excel 2013 if that's any help.如果有帮助,我正在使用 64 位 Excel 2013。

you could create a Worksheet_Change event and handle the cells that have dropdowns您可以创建一个 Worksheet_Change 事件并处理具有下拉列表的单元格

example例子

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$C$4" And Target = "value" Then
        Cells(25, 3) = "Yes"
    End If
End Sub

And if you have No as the default for C25, you don't need code for it如果 C25 的默认值为 No,则不需要代码

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

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