【问题标题】:How to get the name of a range referenced by a drop down list in excel VBA如何获取excel VBA中下拉列表引用的范围名称
【发布时间】:2020-04-23 17:21:33
【问题描述】:

I have a worksheet event where a userform is triggered whenever a drop down list is selected.下拉列表在 sheet1 中,而引用在 sheet2 中使用命名范围。现在我需要该工作表事件来仅触发我的用户表单以获取引用特定命名范围的下拉列表。我打算用...

If Not Intersect(Target, Range("NAMED_RANGE_1")) Is Nothing Then
  //do not show userform, be happy!
else
  //show userform, you are awesome! 

但我无法选择下拉列表的引用命名范围。谁能指导我如何获取所选下拉列表的命名范围?

谢谢!

【问题讨论】:

  • 确保NAMED_RANGE_1Target 在同一个工作表中。否则它们不能相交。

标签: excel vba


【解决方案1】:

您可以通过以下方式获取参考列表(我假设您使用的是 Worksheet_SelectionChange(...) 函数):

On Error GoTo endSub   ' skip if no validation set for Target
If Target.Validation.Formula1 <> "=NAMED_RANGE_1" Then
    ' do not show userform, be happy!
Else
    ' show userform, you are awesome!
End If

endSub:
    Exit Sub

【讨论】:

    猜你喜欢
    • 2021-01-24
    • 1970-01-01
    • 2015-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多