提示:其它语言是由 Google 机器翻译的。 你可以访问 English 版本。
登录
x
or
x
x
马上登记
x

or

如何创建下拉列表,但在Excel中显示不同的值?

在Excel工作表中,我们可以使用数据验证功能快速创建下拉列表,但是,您是否曾尝试在单击下拉列表时显示不同的值? 例如,我在列A和列B中有以下两列数据,现在需要使用名称列中的值创建一个下拉列表,但是当我从创建的下拉列表中选择名称时,相应的Number列中的值显示如下所示。 本文将介绍解决此任务的详细信息。

doc下拉不同的值1

创建下拉列表,但在下拉列表单元格中显示不同的值

Office选项卡在Office中启用选项卡式编辑和浏览,使您的工作更轻松......
Kutools for Excel - 最佳办公生产力工具将解决您的大部分Excel问题
  • 重用任何东西: 将最常用或最复杂的公式,图表和其他任何内容添加到您的收藏夹中,并在将来快速重复使用它们。
  • 超过20文本功能: 从文本字符串中提取数字; 提取或删除部分文本; 将数字和货币转换为英语单词...
  • 合并工具:多个工作簿和表格合二为一; 合并多个单元格/行/列而不丢失数据; 合并重复行和总和...
  • 拆分工具:根据价值将数据拆分为多个表格; 一个工作簿到多个Excel,PDF或CSV文件; 一列到多列......
  • 粘贴跳过 隐藏/过滤行; 数和总和 按背景颜色; 创建邮件列表和 通过Cell的价值发送电子邮件...
  • 超级过滤器: 创建高级过滤方案并应用于任何工作表; 排序 按周,日,频率等; 筛选 通过大胆,公式,评论......
  • 超过300强大的功能; 适用于Office 2007-2019和365; 支持所有语言; 在公司轻松部署; 全功能60天免费试用。

创建下拉列表,但在下拉列表单元格中显示不同的值

要完成此任务,请按照以下步骤进行操作:

1。 在下拉列表中为要使用的单元格值创建一个范围名称,在本例中,我将输入名称下拉框 名称框,然后按 输入 键,看截图:

doc下拉不同的值2

2。 然后选择要插入下拉列表的单元格,然后单击 数据 > 数据验证 > 数据验证,看截图:

doc下拉不同的值3

3。 在 数据验证 对话框下 设置 标签,选择 名单 来自 下拉,然后单击 doc下拉不同的值5 按钮来选择您想要用作下拉值的名称列表 来源 文本框。 看截图:

doc下拉不同的值4

4。 插入下拉列表后,请右键单击活动工作表选项卡,然后选择 查看代码 从上下文菜单中,并在打开 Microsoft Visual Basic的应用程序 窗口中,将以下代码复制并粘贴到空白模块中:

VBA代码:从下拉列表中显示不同的值:

Private Sub Worksheet_Change(ByVal Target As Range)
'Updateby Extendoffice 20161026
    selectedNa = Target.Value
    If Target.Column = 5 Then
        selectedNum = Application.VLookup(selectedNa, ActiveSheet.Range("dropdown"), 2, False)
        If Not IsError(selectedNum) Then
            Target.Value = selectedNum
        End If
    End If
End Sub

doc下拉不同的值6

注意:在上面的代码中,数字 5 如果Target.Column = 5那么 脚本是您的下拉列表中的列号,“下拉“在这 selectedNum = Application.VLookup(selectedNa,ActiveSheet.Range(“dropdown”),2,False) 代码是您在步骤1中创建的范围名称。 你可以改变他们到你需要的。

5。 然后保存并关闭此代码,现在,当您从下拉列表中选择一个项目时,相同的单元格中会显示一个相对不同的值,请参阅截图:

doc下拉不同的值7


演示:创建下拉列表,但在Excel中显示不同的值

Kutools for Excel:比200方便的Excel加载项,可以在60天免费试用。 下载并免费试用现在!


Kutools for Excel - 最佳办公生产力工具提高80%的生产力

  • 重用: 快速插入 复杂的公式,图表 以及你以前用过的任何东西; 加密单元格 密码; 创建邮件列表 并发送电子邮件...
  • 超级方程式酒吧 (轻松编辑多行文字和公式); 阅读布局 (轻松读取和编辑大量单元格); 粘贴到过滤范围...
  • 合并单元格/行/列 不丢失数据; 分裂细胞含量; 组合重复的行/列...防止重复的细胞; 比较范围...
  • 选择复制或唯一 行; 选择空行 (所有细胞都是空的); 超级查找和模糊查找 在许多工作簿中; 随机选择......
  • 精确复制 多个单元格而不更改公式参考; 自动创建参考 多张表; 插入项目符号,复选框等等......
  • 提取文本,添加文本,按位置删除, 删除空间; 创建和打印分页小计; 在单元格内容和注释之间转换...
  • 超级过滤器 (将过滤方案保存并应用到其他工作表); 高级排序 按月/周/日,频率等; 特殊过滤器 用粗体,斜体......
  • 结合工作簿和工作表; 根据键列合并表; 将数据拆分为多个表格; 批量转换xls,xlsx和PDF...
  • 超过300强大的功能。 支持Office / Excel 2007-2019和365。 支持所有语言。 在您的企业或组织中轻松部署。 全功能60天免费试用。
kte tab 201905

Office选项卡为Office提供选项卡式界面,使您的工作更轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,Publisher,Access,Visio和Project。
  • 在同一窗口的新选项卡中打开并创建多个文档,而不是在新窗口中。
  • 通过50%提高您的工作效率,每天为您减少数百次鼠标点击!
官方底部
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Rizwan Ahmad · 13 days ago
    i want to select multiple option from dropdown list.
    result like this: AA1001,BB1002
    is it possible?
  • To post as a guest, your comment is unpublished.
    Mike · 3 months ago
    Anyone know how to get this to work in google sheets?
  • To post as a guest, your comment is unpublished.
    Marcus · 4 months ago
    How would the code Need to Change if I wanted to create a reference/link in E1 to the source of the Dropdown list based on the selected value?
    The Benefit would be that In case of a change in the dropdown source (e.g. "Henrik" => "Hendrik" the change would automatically get reflected in E1.
  • To post as a guest, your comment is unpublished.
    William · 4 months ago
    In this example, what if you want it to look at a value in each of the cells in 5, but put the value in the adjacent cell in 6
  • To post as a guest, your comment is unpublished.
    ty · 5 months ago
    this doesn't work in current versions of excel- outdated. Data validation then list no longer shows up in vba as an excel object have tried already multiple times and it doesn't show up.
  • To post as a guest, your comment is unpublished.
    Charmin · 2 years ago
    How does the formula work when you want to list the data on a separate sheet/tab in the workbook?
  • To post as a guest, your comment is unpublished.
    Charmin · 2 years ago
    How does the formula the work when you want to add the data on a separate sheet in the workbook? I want to hide the data.
    • To post as a guest, your comment is unpublished.
      Phyo · 10 months ago
      Change here bro!
      selectedNum = Application.VLookup(selectedNa, Worksheets("YourSheetName").Range("dropdown"), 2, False)
      • To post as a guest, your comment is unpublished.
        César López - Sofpromed · 1 months ago
        "YourSheetName" makes reference to the sheet that contains the data range or the sheet where I want to use the dropdwon list?
  • To post as a guest, your comment is unpublished.
    Mike K · 2 years ago
    Nothing more frustrating than typing in a detailed question only to have it blown away. If you type the wrong 6 digit code to verify your human, it wipes out the posted message. Might want to fix that.

    Now my comment is this: I tried to do the exact same thing you showed in the video and written instructions and all I get is when I select a name in the list is the name and not the number. Also, how is this even working since data validation should limit the choices to what's in the list only. How is this tricking the system?

    In the past I've always had to assign vba code to button or a shortcut, how is this code activated? How do you test to make sure it's working?
  • To post as a guest, your comment is unpublished.
    Lee Ann Brennan · 2 years ago
    What if I want to do more than one dropdown that returns different values on the same worksheet? Can you show me an example of the coding for two or more?
    • To post as a guest, your comment is unpublished.
      Tony · 10 months ago
      Lee Ann

      If you just copy and paste the code from the If to the EndIf and change the column # and Table it should work:


      Sub Worksheet_Change(ByVal Target As Range)
      selectedNa = Target.Value
      If Target.Column = 5 Then
      selectedNum = Application.VLookup(selectedNa, ActiveSheet.Range("dropdown"), 2, False)
      If Not IsError(selectedNum) Then
      Target.Value = selectedNum
      End If
      End If
      If Target.Column = 9 Then
      selectedNum = Application.VLookup(selectedNa, ActiveSheet.Range("dropdown1"), 2, False)
      If Not IsError(selectedNum) Then
      Target.Value = selectedNum
      End If
      End If
      End Sub

      I'm not saying this is the correct way but it worked on my test version. I'm using Excel 2013
  • To post as a guest, your comment is unpublished.
    Tina · 2 years ago
    Can this be done on different sheets? I mean, on sheet1 the dropdown and on sheet2 the range. How do I have to code this? Thanks in advance. Tina.