本文转自:http://stackoverflow.com/questions/10657811/set-drop-down-values-based-on-vlookup

问:

I have a worksheet UserEntry with 2 columns, Block and Address.

I want to validate both of these based on another worksheet Validation with the same column names.

The data on the Validation sheet is as follows:

Block | Address
---------------
001 | 101
001 | 101.3
001A | 35
020-1 | 203
020-1 | 203.5
020-1 | 204.1 ... 答:
5down voteaccepted

You didn't mention VBA but here is a solution that uses it.

Step 1

Create a master table of Block-Address relationships. Make sure this is sorted on Block. I used Sheet1:

Cell E2 is important. You don't actually have to put anything there, but the macro will use it. Cell E3 is for show only, but you will use the formula (which is commented out here so you can see it)  momentarily.

Step 2

Create a named range. The formula in Refers to: is what you saw in E3 above, and you can see the reference to cell E2 here. The formula for your convenience is

=OFFSET($A$1,MATCH($E$2,$A:$A,0)-1,1,COUNTIF($A:$A,$E$2),1)

Step 3

Set up a new worksheet (Sheet2) where the data entry will happen. Create data validation for the Address column as shown.

Step 4

Open the VBA editor and paste this code in the module for Sheet2. You can remove the Debug statement if you wish. Again note the reference to cell E2 on Sheet1:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Debug.Print "fired on " & ActiveCell.Address
If Not Application.Intersect(Target, Range("B:B")) Is Nothing Then
Sheets("Sheet1").Range("E2").Value = ActiveCell.Offset(0, -1).Value
End If
End Sub

Step 5

Enjoy. Your data validation is now context sensitive. Examples:

答:

You can use a dynamic named range for this.

Assumptions:

  1. Validation list is sorted A..Z
  2. Validation list is in range Validation!A:B
  3. Validation list includes headings in row 1
  4. On sheet UserEntry the Address cell to be validated is one cell to the right of the ented Block
  5. Tried and tested on Excel 2010

Create a Named Range to use as validation source (I've used name ValList):

=OFFSET(Validation!$B$1,MATCH(INDIRECT(ADDRESS(CELL("row"),CELL("col")-1)),Validation!$A:$A,0)-1,0,COUNTIF(Validation!$A:$A,INDIRECT(ADDRESS(CELL("row"),CELL("col")-1))),1)

Add Data Validation to the required cells: Allow List, Source =ValList

  1. Uses INDIRECT, ADDRESS and CELL to get a refernce to the user entered Block relative to the active cell
  2. Uses MATCH and COUNTIF to get the position and size of the matching Blocks in the validation list
  3. Uses OFFSET to set the return range to the addreesses matching the enterd block

[转]excel set drop-down values based on vlookup的更多相关文章

  1. excel手机号码归属地批量公式查询 vlookup函数

    Excel手机号码归属地 批量公式查询 vlookup函数 xls 手机号码 添加一列 地区归属地 使用      公式:=(VLOOKUP(LEFT(B2,7),号段数据库!B:D,2,0)& ...

  2. pandas实现excel中的数据透视表和Vlookup函数功能

    在孩子王实习中做的一个小工作,方便整理数据. 目前这几行代码是实现了一个数据透视表和匹配的功能,但是将做好的结果写入了不同的excel中, 如何实现将结果连续保存到同一个Excel的同一个工作表中?还 ...

  3. excel两张表数据匹配数据(VLOOKUP)

    最近项目中需要跨项目导入数据,现整理Excel的一个小技能,记录如下. 第一步:我们打开一个excel表,创建数据如下. 第二步:我们把光标定位在需要展示数据的单元格中,如下图所示. 第三步:我们可以 ...

  4. 个人永久性免费-Excel催化剂功能第38波-比Vlookup更好用的查找引用函数

    谈起Excel的函数,有一个函数生来自带明星光环,在表哥表姐群体中无人不知,介绍它的教程更是铺天盖地,此乃VLOOKUP函数也.今天Excel催化剂在这里冒着被火喷的风险,大胆地宣布一个比VLOOKU ...

  5. Excel 查找函数(二):VLOOKUP

    函数讲解 [语法]VLOOKUP(lookup_value, table_array, col_index_num, [range_lookup]) [参数]函数一个有四个参数,其中有三个必填参数:一 ...

  6. 以ORM的思路来从Excel文件中读取JSON数据列表

    1.一个常见的问题就是如何读取excel. 这里面有几个分支的问题,一个是如何使用poi读取excel,网上例子很多,但是这只解决了第一步.如何将excel读取入一定的数据结构这是第二个问题,还有就是 ...

  7. Graphics-Processing Architecture Based on Approximate Rendering

    BACKGROUND The present invention generally relates to the processing of graphics data, and particula ...

  8. excel VLOOKUP函数的使用方法 .

    VLOOKUP函数是Excel中几个最重函数之一,为了方便大家学习,兰色幻想特针对VLOOKUP函数的使用和扩展应用,进行一次全面综合的说明.本文为入门部分 一.入门级 VLOOKUP是一个查找函数, ...

  9. excel VLOOKUP函数的用法

    VLOOKUP函数是Excel中几个最重函数之中的一个,为了方便大家学习,兰色幻想特针对VLOOKUP函数的使用和扩展应用,进行一次全面综合的说明.本文为入门部分 一.入门级 VLOOKUP是一个查找 ...

随机推荐

  1. sencha gridpanel改变单元格颜色

    标题列包含 审核通过则绿色,包含拒绝为红色: { xtype: 'gridcolumn', renderer: function(value, metaData, record, rowIndex, ...

  2. ActiveReports 9 新功能:借助目录(TOC)控件为报表添加目录功能

    在最新发布的ActiveReports 9报表控件中添加了多项新功能,以帮助你在更短的时间里创建外观绚丽.功能强大的报表系统,本文将重点介绍新增文档目录控件(TOC),通过拖拽操作便可添加报表目录. ...

  3. activiti 工作流

    1. 工作流的概念 工作流(Workflow),就是“业务过程的部分或整体在计算机应用环境下的自动化”,它主要解决的是“使在多个参与者之间按照某种预定义的规则传递文档.信息或任务的过程自动进行,从而实 ...

  4. Mysql denied for user 'odbc@localhost' || denied for user 'root@localhost'

    1. Question Description: 1.1  mysql  version:  mysql-5.7.11-win64.zip 1.2  if you connect to the mys ...

  5. PHP 操作mongodb api大部分方法

    <?php /* PHP mongodb * 全部curd操作 * @author:xiaojiang * @date: 2014-10-27 */ //查看 mongo类版本 1.30 以后版 ...

  6. velocity merge作为工具类从web上下文和jar加载模板的两种常见情形

    很多时候,处于各种便利性或折衷或者通用性亦或是限制的原因,会借助于模板生成结果,在此介绍两种使用velocity merge的情形,第一种是和spring mvc一样,将模板放在velocityCon ...

  7. jQuery Devrama Slider 幻灯片

    Devrama Slider 是个图像滑块,带有许多非常有趣的特性. 它不仅支持图像还支持 HTML 内容. 响应式 方便 CSS3 转换 转换效果 进度条 高级的预加载和延迟加载 CSS 自定义 用 ...

  8. Android 带清除功能的输入框控件EditText

    1.效果图      2.源码下载 http://download.csdn.net/detail/yanzi2015/8864603 3.相关博客 http://www.cnblogs.com/to ...

  9. Ubuntu14.04下安装Hadoop2.5.1 (单机模式)

    本文地址:http://www.cnblogs.com/archimedes/p/hadoop-standalone-mode.html,转载请注明源地址. 欢迎关注我的个人博客:www.wuyudo ...

  10. Static Cell-静态TableView

    使用静态TableView有两个前提,1.要在Storyboard上  2.需要使用TableViewController PS:如果需要设置不同的cell的高度不同的话,还是需要使用tableVie ...