Excel 2010比较多列(2列到2其他列)

我想比较2列和其他2列。

问题是,我希望能够search整个列的第二组2列。 例如, C2 and D2中的值可以匹配I23 and J23I101 and J101

我发现有关VLOOKUP具有用于比较一列到另一列的function。

 =VLOOKUP(C2;$I$2:$K$343;3) 

在上面的函数中,将C2值查findI列(从单元格2到343),如果在该列中find,则会返回匹配单元格右侧的第3个单元格的值。

结合这个问题的答案如何在Excel中比较多个列? 这可以工作,但我正在寻找一个“干净”的方式来做到这一点。

提前致谢

这是用户定义的函数,将执行2列查找。 把它看作是一个vlookup

LookupPair是一对单元格。 (C2:D2)在你的例子。 除此之外,任何一对并排的单元都会导致错误。

LookupRange是包含匹配对列返回列的列。 例如(I1:K101)在你的例子。 LookupRange必须至less包含两列或者生成一个错误。

ReturnColLookupRange中包含要返回的值的列号。 (与Col_index_num中的Col_index_num相同)。

该function只能完全匹配。

 Function DoubleColMatch(LookupPair As Range, LookupRange As Range, ReturnCol As Integer) As Variant Dim ReturnVal As Variant Dim Col1Val As Variant Dim Col2Val As Variant Dim x As Long If LookupPair.Rows.Count > 1 _ Or LookupPair.Columns.Count <> 2 _ Or LookupRange.Columns.Count < 2 _ Or ReturnCol < 1 _ Or ReturnCol > LookupRange.Columns.Count _ Then ReturnVal = CVErr(xlErrRef) Else Col1Val = LookupPair.Cells(1, 1) Col2Val = LookupPair.Cells(1, 2) ReturnVal = CVErr(xlErrNA) For x = 1 To LookupRange.Rows.Count If LookupRange.Cells(x, 1) = Col1Val _ And LookupRange.Cells(x, 2) = Col2Val Then ReturnVal = LookupRange.Cells(x, ReturnCol).Value Exit For End If Next x End If DoubleColMatch = ReturnVal End Function