如何将 Excel 中的单元格值限制为另一个工作表中的选项?
在 Excel (2003) 中,我想将单元格中的值选择限制为另一个电子表格中允许的值。
例如,在“货币”工作表中
EUR,1.1 GBP,1.0 USD,1.5
(即两列,三行)
在我的主工作表中,我希望有一个“货币”列,其中唯一允许的值来自“货币”工作表中的 A 列,即单元格只能包含“EUR”、“GBP”或“USD”。 (在其他地方,我将使用它作为查找来获取汇率,即 B 列。)
如何限制单元格中的值?拥有一个像 Windows 组合框一样的下拉菜单,从另一张表中填充会很棒。
任何使用公式、VBA 或其他方式的答案都可以。即使指向相关文档的指针也很棒(我已经看过,但我不确定要寻找什么)。
使用 LibreOffice 得到答案也很有帮助,因为我还没有最终确定电子表格程序的选择,但我认为在 Excel 中得到答案的机会更大。
In Excel (2003), I want to limit the selection of values in a cell to allowable values from another spreadsheet.
For example, in the sheet "Currencies" I have
EUR,1.1 GBP,1.0 USD,1.5
(That's two columns, three rows)
In my main sheet I'd like to have a Currency column, in which the only allowable values are from column A in the Currencies sheet, i.e. the cell can contain only 'EUR', 'GBP', or 'USD'. (Elsewhere I'll be using that as a lookup to get the exchange rate, which is column B.)
How can I restrict the value in the cell? Having a dropdown like a windows combo box populated from the other sheet would be great.
Any answers using formulas, VBA, or whatever will be fine. Even a pointer to the relevant documentation would be great (I have looked, but I'm not sure what to look for).
Also helpful would be answers using LibreOffice, since I haven't finalized the choice of spreadsheet program, but I thought I'd have a better chance getting an answer in Excel.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在这种情况下不需要 VBA。使用内置的“数据验证”功能。
选择要添加组合框的单元格,然后选择“数据”、“验证”。
选择“列表”作为选项,然后在“源”框中放置一个单元格范围,或者放置一个以逗号分隔的值列表(如果您想对其进行硬编码)。
如果要填充列表的范围位于另一个工作表上,则无法使用标准
=sheet2!a1:a4
样式引用它。您必须创建一个命名范围,并通过该名称引用它。VBA isn't necessary in this case. Use the built-in "Data Validation" feature.
Select the cell you want to add the combo box to, and choose Data, Validation.
Select "List" as the option, and either put a cell range in the "Source" box, or a comma-delimited list of values (if you want to hard-code it).
If the range you want to populate the list is located on another worksheet, you can't refer to it using the standard
=sheet2!a1:a4
style. You'll have to create a named range, and refer to it by that name.为什么不使用下拉菜单?
http://office.microsoft.com/en-us/excel-help/create-a-drop-down-list-from-a-range-of-cells-HP005202215.aspx
Why not use a dropdown?
http://office.microsoft.com/en-us/excel-help/create-a-drop-down-list-from-a-range-of-cells-HP005202215.aspx