本文介绍了遍历 Excel 下拉列表/验证列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有验证列表的单元格,该列表会根据其他设置而变化.是否可以在代码中遍历该单元格?是否也可以将该单元格设置为列表中的第 n 项?

I have a cell with a validation list that changes depending on other settings. Is it possible to iterate through that cell in code?Is it also possible to set that cell to the nth item in the list?

示例:E2 的下拉列表取决于为 D2 选择的内容.我希望能够遍历 E2 中的任何列表,而无需检查 D2.

Example:The drop down for E2 depends on what was selected for D2. I would like to be able to iterate through whatever list is in E2 without having to check D2.

谢谢.

推荐答案

这对你有用

Sub loopthroughvalidationlist()
     Dim inputRange As Range
     Dim c As Range
     Set inputRange = Evaluate(Range("D2").Validation.Formula1)
     For Each c In inputRange
        '... do something with c.Value
    Next c
End Sub

这篇关于遍历 Excel 下拉列表/验证列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 04:34