从excel vba中的Dropdown选择一个特定的项目 [英] Selecting a specific item from Dropdown in excel vba

查看:737
本文介绍了从excel vba中的Dropdown选择一个特定的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的办公室制作仪表盘。这一切都有效,但是我想添加一个选项,而不是在下拉列表中搜索250多个项目,您也可以单击一个单元格,下拉列表将更改为该值,并且分配的宏将针对该下拉列表运行。到目前为止,我无法弄清楚如何让vba从下拉列表中选择一个特定的项目。我可以改变文字,但是没有选择下拉列表的索引。



任何建议?

解决方案

如果您正在使用ActiveX下拉列表(组合框),您可以在下拉列表中更改所选值:

  ComboBox1.Value =新值

如果您使用数据验证作为下拉列表,那么您只需要更改单元格值即可更改任何其他单元格:

 '假设下拉列表(数据验证)在单元格(1,1)
cells(1,1)=新值
/ pre>

此外,您可以查看我在博客上写的关于在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆