Excel数据复制

我在工作表中有两列,如下面的列表。

我想要做的是拉第二列的值,但只有当相应的第一列值匹配我指定的值。 这我可以做一个Vlookup但是我也想能够指定第一列匹配数组的行号。

例如,如果我将值设置为'2',行号设置为'2',那么它会给我14的值,因为它与列1中的第一个值相匹配,并创build一个数组,然后给我该数组的第二行是14。

有任何想法吗?

1 10 1 11 1 12 2 13 2 14 2 15 3 16 3 17 3 18 

如果您的数据按照您在示例中的sorting,即。 按第一列升序,第二列升序。 那么你可以使用OFFSET()INDEX()MATCH()

 =OFFSET(INDEX(second_column,MATCH(lookup_a,first_column,0)),entry_row-1,0) 

首先获得与您的查找值匹配的第一个单元格的INDEX(..., MATCH())的单元格地址,然后OFFSET()函数将该单元格在该组中要求的行数降低。 当然,这完全取决于所描述的分类。

使用<code> OFFSET()</ code>查找两行

如果你想在未分类的第二列(但仍然分组在第一列)中的第k个最小的条目,那么你可以使用:

 =SMALL(OFFSET(second_column,MATCH(lookup_a,first_column,0)-1,0,MATCH(lookup_a,first_column,1)-MATCH(lookup_a,first_column,0)+1,1),entry_row) 

这样做的好处是,如果您移出选区,就会返回#N/AIFERROR(...., "")

或者,对未sorting的第二列数据使用第一种方法,并仅检查偏移量以查看它是否保留查找值,则可以使用:

 =IF(OFFSET(OFFSET(INDEX(second_column,MATCH(lookup_a,first_column,0)),entry_row-1,0),0,-1)=lookup_a,OFFSET(INDEX(second_column,MATCH(lookup_a,first_column,0)),entry_row-1,0),"") 

答案使用VBAselect“查找”的第二个结果可以扩展到您的案例,使用您正在查找的发生次数作为input。

这是Excel Lookup第n个发生/实例的改编:

 Function FindNth(Table As Range, Val1 As Variant, Val1Occrnce As Integer, ResultCol As Integer) 'Finds the Nth value in the first Column of a table that has a stated value on the same row in another Column. Dim i As Integer Dim iCount As Integer Dim rCol As Range iCount = 0 For i = 1 To Table.Rows.Count If (Table.Cells(i, 1) = Val1) Then iCount = iCount + 1 End If If iCount = Val1Occrnce Then FindNth = Table.Cells(i, ResultCol) Exit For End If Next i End Function 

下面是使用用户定义函数的结果(公式栏显示单元格G3中的公式):

在这里输入图像说明