本文转自: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. SystemMenu类的用法

    先声明对象以及相应常数: //SystemMenu对象 private SystemMenu m_systemMenu = null; // ID 常数定义 (可变,只要不与系统冲突即可) priva ...

  2. 老毛桃安装Win8(哪里不会点哪里,so easy)

    先来一张美女图,是不是很漂亮呢!继续往下看! 英雄不问出路,美女不看岁数!求推荐啊! 每次碰到妹子找我装系统的时候我都毫不犹豫的答应了,心里暗暗想到:好好表现啊!此刻的心情比见家长还要激动和紧张! 有 ...

  3. 狂屌的Windows下的定时任务工具xStarter

    xStarter是一款将某些常规计算机操作自动化进行为目的的程序. 它不能为你生成word文件,但是它可以周期性地为你备份文件以保持完整性. 程序的特点有:加强的任务计划工具;在系统事件上执行任务;用 ...

  4. NTFS碎片

    在Windows操作系统中查看各分区的文件系统: fsutil fsinfo ntfsinfo c: (查看C:盘的文件系统) fsutil fsinfo ntfsinfo d: (查看D:盘的文件系 ...

  5. spring编程式刷新/重新加载applicationcontext/dispatchservlet(正确版)

    有些时候,尤其是在开发应用框架的时候,由于某些原因无法或者很难重启tomcat或者reload应用,但是配置又需要动态生效,这个时候通常希望通过reload spring applicationcon ...

  6. .NET 面试题整理

    概念类 请你说说.NET中类和结构的区别? 答:结构和类具有大体的语法,但是结构受到的限制比类要多. 结构不能申明有默认的构造函数,为结构的副本是又编译器创建和销毁的,所以不需要默认的构造函数和析构函 ...

  7. java多线程系列4-线程池

    在之前的文章中,学习了通过实现java.lang.Runnable来定义类,以及像下面这样创建一个线程来运行任务: Runnable task = new TaskClass(task); new T ...

  8. iOS 杂笔-20(UIView和CALayer的区别与联系)

    iOS 杂笔-20(UIView和CALayer的区别与联系) 每个 UIView 内部都有一个 CALayer 在背后提供内容的绘制和显示,并且 UIView 的尺寸样式都由内部的 Layer 所提 ...

  9. UVa 107 - The Cat in the Hat (找规律,注意精度)

    题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...

  10. 如何写BaseDomain

    上图摘自<Spring3.x企业应用开发实战> 提到了使用org.apache.commons.lang3.builder ToStringBuilder进行toString方法的统一. ...