下拉button更改

我有2个下拉列表,我已经分配了一个macros(相同的macros到两个下拉列表)。 第一个下拉列表中的值是:{二月,三月,四月,五月}。 第二个下拉列表中的值是:{销售量,销售额,利润}。 现在我想在我的Excelmacros中添加一个更多的function。 当我从第一个下拉列表中selectMay时,一个vbok mssgbox应该会显示一条消息。 但是,当第一个下拉列表中的May已经被选中,并且我们在第二个下拉列表中更改了值时,那么mssgbox不应该一次又一次地出现。 如在,它应该只出现在下拉的变化1。 任何帮助,将不胜感激 :)

您需要为第一个下拉框指定一个不同的macros。 它只需要执行5月份的testing,然后调用第二个下拉框的macros(或者在testing之前 – 只要你喜欢)。

既然你已经能够分配一个和相同的macros到这两个下拉框,你必须使用表单控件,而不是ActiveX控件。

因此,您可以使用macros中的Application.Caller来找出哪个下拉框导致macros运行:

 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 

通过这个,你可以根据两个下拉框中的哪一个被改变来改变macros中发生的事情:

 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 Sub