gpt4 book ai didi

vba - Excel将下拉列表的所有数据提取到列中

转载 作者:行者123 更新时间:2023-12-04 20:12:18 29 4
gpt4 key购买 nike

我从其他工作表中复制了一个下拉列表单元格并尝试获取其所有项目名称。下拉列表由 this 通过 excel 属性创建链接,不使用 组合框 .有没有办法获取下拉列表的所有项目?
表示获取映射到下拉列表的原始列表。

我也尝试通过 VB 脚本来获取它,但它不起作用。

Dim dd As DropDown
Set dd = ActiveSheet.DropDowns("MyDropDown")

当我调试该代码时,它显示“无法获取工作表类的下拉列表属性”错误
Set dd = ActiveSheet.DropDowns("MyDropDown")

线和这个 Excel dropdowns in VBA: "Unable to get the DropDowns property of the Worksheet class"
没有帮助我。
ActiveSheet.DropDowns("MyDropDown") 仅适用于组合框?
那么我如何使用 excel 属性或 VB 脚本获取所有项目?

最佳答案

啊,您最初的问题并没有明确说明您正在使用数据验证。要遍历数据验证列表中的所有项目,您可以使用以下代码:

Sub loopthroughvalidationlist()
Dim inputRange As Range
Dim c As Range
' Change range below to first cell in your list
Set inputRange = Evaluate(Range("J6").Validation.Formula1)
For Each c In inputRange
MsgBox (c)
Next c
End Sub

关于vba - Excel将下拉列表的所有数据提取到列中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35492938/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com