vba Excel 单元格中的下拉列表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2070256/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 10:13:27  来源:igfitidea点击:

Drop-down list in Excel cell

excelexcel-vbams-officevba

提问by Captain Comic

I have a simple Excel speadsheet where in one column i write string values. What I need is to define some predefined values and instead of typing string select it from dropdown list. For instance for a column Store Name I want to select "Reebok", "Adidas" and so on.

我有一个简单的 Excel 电子表格,我在其中的一列中写入字符串值。我需要的是定义一些预定义的值,而不是输入字符串,从下拉列表中选择它。例如,对于列 Store Name,我想选择“Reebok”、“Adidas”等。

I understand that there can be several ways how to implement it,even VBA. I use Office 2007.

我知道有几种方法可以实现它,甚至是 VBA。我使用的是 Office 2007。

Please advice.

请指教。

回答by Psytronic

What I do is have column A with all the values in, select the cells which need the list (or do this to one, and do the cell corner drag to the other cells), choose Data->Validation from the menu, in Settings tab change Allow from "Any Value" to "List". Then click the button which appears next to the new entry box.

我所做的是让 A 列包含所有值,选择需要列表的单元格(或执行此操作,然后将单元格角拖动到其他单元格),从菜单中选择数据->验证,在设置中选项卡将允许从“任何值”更改为“列表”。然后单击出现在新输入框旁边的按钮。

Select the cells in column A, then click the button again. Then click Ok.

选择 A 列中的单元格,然后再次单击该按钮。然后单击确定。

Then hide Column A, so you can't see them (Just for display purposes).

然后隐藏 A 列,这样您就看不到它们(仅用于显示目的)。

You don't have to use Column A, it's just that way you don't have to worry about moving the list if your table extends down or outwards.

您不必使用 A 列,这样您就不必担心在表格向下或向外延伸时移动列表。