我有两个下拉列表,我已经分配了一个宏(两个下拉列表都有相同的宏)。第一个下拉列表中的值为:{Feb,三月,四月,五月}。第二个下拉列表中的值为:{销售额,销售额,利润}。现在,我想在我的excel宏中再添加一个功能。当我从第一个下拉列表中选择May时,会出现一个vbok mssgbox,并显示一条消息。但是,当在第一个下拉列表中选择了May,并且我们在第二个下拉列表中更改了值时,mssgbox应该不会一次又一次地出现。与中一样,它应该只在dropdown1中发生更改时才会出现。如有任何帮助,我们将不胜感激:)
发布于 2016-05-05 18:26:11
您需要为第一个下拉框指定一个不同的宏。它只需要对May执行测试,然后调用第二个下拉框中的宏(或者在测试之前--你喜欢的那样)。
发布于 2016-05-05 20:21:03
由于您已经能够将一个相同的宏赋给两个下拉框,因此您必须使用表单控件而不是ActiveX控件。
因此,您可以使用宏中的Application.Caller来找出哪个下拉框导致宏运行:
Sub SameMacroForTwoDropDownBoxes()
'The following line of code will tell you
' in a message box which of the two
' drop-down boxes initiated the macro
MsgBox Application.Caller
End Sub这样,您就可以根据两个下拉框中的哪一个已更改来更改宏中发生的内容:
Sub SameMacroForTwoDropDownBoxes()
'The following line of code will tell you
' in a message box which of the two
' drop-down boxes initiated the macro
Select Case Application.Caller
Case "Drop Down 1"
MsgBox "The first drop-down box has been changed."
Case "Drop Down 2"
MsgBox "The second drop-down box has been changed."
Case Else
MsgBox "No idea where this was coming from..."
End Select
End Subhttps://stackoverflow.com/questions/37047875
复制相似问题