首页 > 解决方案 > Excel 2010 - 如何从 2 个列表创建验证列表并给它们倾斜

问题描述

如何从 2 个列表中创建 excel 2010 中的验证列表并给它们倾斜?

例如:

Column A:
1 Boys Names
2 Danny
3 Sam
3 Luke


Column B:
1 Girls Names
2 Sarah
3 Ellen
4 Jessica

在 CI 列中,希望能够从 A+B 列中选择“名称”而没有任何依赖关系。我希望能够在下拉列表中看到:

Boys Names
-------------------
Danny
Sam
Luke
Girls Names
--------------------
Sarah
Ellen
Jessica

我不想选择“男孩名字”和“女孩名字”,但只能选择:Danny、Sam、Luke、Sarah、Ellen 或 Jessica。可能吗?

标签: excelvalidation

解决方案


对于这样的列表:

男孩名字
----------
丹尼·
萨姆
·卢克

女孩名字
---------
莎拉
·艾伦·
杰西卡

您可以在工作表模块中包含以下 VBA 代码:

Private Sub Worksheet_Change(ByVal Target As Range)
    Case "Boys Names", "Girls Names", "-----------": 'If the value is one of these options
        Target.Clear 'Blank the cell
    End Select
End Sub

可以使用If Target.Value="Boys Names" OR Target.Value="Girls Names"OR Target.Value="-----------" Then,但Switch语句更简单、更整洁。您可能还想使用Intersect来检查目标单元格,以防您在工作表的另一部分需要任何这些值。


推荐阅读