从excel vba中的Dropdown选择一个特定的项目 [英] Selecting a specific item from Dropdown in excel vba
问题描述
任何建议?
如果您正在使用ActiveX下拉列表(组合框),您可以在下拉列表中更改所选值:
ComboBox1.Value =新值
如果您使用数据验证作为下拉列表,那么您只需要更改单元格值即可更改任何其他单元格:
'假设下拉列表(数据验证)在单元格(1,1)
/ pre>
cells(1,1)=新值
此外,您可以查看我在博客上写的关于在VBA中使用下拉列表的文章 Excel VBA下拉列表
I'm working out a dashboard for my office. It all works, but I wanted to add in an option that instead of searching through 250+ items in a dropdown, you could also click on a cell and the dropdown would change to that value, and the assigned macro would run for that dropdown. So far I can't figure out how to have vba select a specific item from a dropdown. I can have the text change, but that doesn't select the index of the dropdown.
Any suggestions?
解决方案If you are using an ActiveX drop down list, (a combobox) this is how you would change the selected value in the drop down list:
ComboBox1.Value = "New Value"
If you are using data validation as a drop down list, then you just need to change the cell value as you would change any other cell:
'assuming the drop down list (data validation) is in Cell(1, 1) cells(1,1) = "New Value"
Also you could check this article I've written on my blog about working with drop down lists in VBA Excel VBA Drop Down Lists
这篇关于从excel vba中的Dropdown选择一个特定的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!