首页 > 解决方案 > 从表单控件获取列表值

问题描述

我的 Excel 工作表中有一个下拉表单控件。它的输入范围是一个命名范围,其中包含另一个命名范围。我希望在更改用户后重定向到选定的名称范围。我很难从下拉控件中直接获取选定的名称范围。我得到的只是 dronwdown 控件的列表值。我做了一个解决方法,并从主命名范围中选择了适当的单元格,但我想知道应该有一种方法可以直接获取所选项目的字符串值。这是我的代码,也是我已经尝试过的。

** 这有效:

Sub GotoNames()
Dim rng As Range, T As Range
    Set rng = ThisWorkbook.Sheets("Panel").Range("NamedRng")
    On Error GoTo errr
Retry:
    With ThisWorkbook.Sheets("Result").DropDowns(1)
       Set T = rng(.Value)
       Application.Goto T.Value2
    End With
    Exit Sub
errr:
    If T.Worksheet.Visible = xlSheetHidden Then
        T.Worksheet.Visible = xlSheetVisible
        resume Retry
    End If
End Sub

但我想要:

Sub GotoNames()
'On Error Resume Next
    With ThisWorkbook.Sheets("Result").DropDowns(1)
        Application.Goto .ControlFormat.List(.ControlFormat.ListIndex) 'OR
        Application.Goto .ListFillRange(.value)
    End With
End Sub

标签: excelvba

解决方案


推荐阅读