excel - 从表单控件获取列表值
问题描述
我的 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
解决方案
推荐阅读
- visual-studio - VS 2017 中新 Xamarin 项目的多个“未找到资源...”和“错误接收项目的父项”
- javascript - 等价于 Javascript 中的 atexit()
- gradle - 使用 Gradle 将文件上传到 Artifactory,无需 maven 发布
- angular - Angular / Jasmine 单元测试中的 spyService 和 throwError() 问题;
- pyspark - 当我以 orc 格式保存数据帧并读取时,pyspark 读取错误
- java - 存储在链表中但不可用的对象的值
- python - pexpect expect(pexpect.EOF) 抛出异常而不输出
- sql - Oracle SQL Developer - 错误:“未在预期的位置找到 FROM 关键字”
- vue.js - Vue2-Highcharts setOptions 语言
- javascript - MochaJS:如何在控制台中预览请求正文?