Excel:查找包含在字符串中的矩阵单元格,并返回相同的行但不同的列 [英] Excel: find matrix cell that contains in a string and return same row but different column

查看:793
本文介绍了Excel:查找包含在字符串中的矩阵单元格,并返回相同的行但不同的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查产品名称中矩阵的单元格值,并返回同一行中的值,但不同的列(列A)。



我使用这个功能,但它只检查一列而不是矩阵:

  = INDEX(A $ 11:A $ 13, (15,6,ROW($ 1:$ 3)* SIGN(MATCH(*& A $ 11:A $ 13&*,B2,0)),1))

简单来说,我想按产品名称计算汽车制造商。

解决方案

这个公式会奏效,长和添加到矩阵只会增加长度:

  = INDEX($ A $ 11:$ A $ 13,IFERROR (综合(15,6,ROW($ 1:$ 3))* SIGN(*& A $ 11:A $ 13&*,A2,0)),1),IFERROR ,ROW($ 1:$ 3)* SIGN(MATCH(*& $ B $ 11:$ B $ 13&*,A2,0)),1),IFERROR(集合(15,6,ROW($ 1 :$ 3)* SIGN(*& $ C $ 11:$ C $ 13&*,A2,0)),1),IFERROR(积分(15,6,ROW($ 1:$ 3)* SIGN(MATCH(*& $ D $ 11:$ D $ 13&*,A2,0)),1),0)))))
pre>

它基本上一直按列查找,直到找到有效的答案。如果更多的模型需要新的话,则需要为数据矩阵中的每一列添加iferror公式。



更快的方法将是UDF: p>

 函数FINDINSTRING(Srch,rng)As String 
Dim strArr()As String
Dim findArr()
Dim i& j& k&

findArr = rng.Value

strArr = Split(Srch,)


对于i = LBound(strArr)To UBound(strArr)
对于j = LBound(findArr,1)到UBound(findArr,1)
对于k = LBound(findArr,2)到UBound(findArr,2)
如果UCase (strArr(i))= UCase(findArr(j,k))然后
FINDINSTRING = findArr(j,1)
退出函数
结束如果
下一个k
下一步j
下一步i

FINDINSTRING =#N / A

结束函数

当放置在工作簿中的模块中时:





从Excel命中 Alt - F11 。在那个窗口中goto Insert ==> Module。在该模块中粘贴以上代码。



这里是更好的解释图片。



它可以直接调用从工作表。在B2中:

  = FINDINSTRING(A2,$ A $ 11:$ D $ 13)

然后数据矩阵的大小无关。


I want to check which cell value of matrix contains in "Product name" and return a value in the same row, but different column (column A).

I using this function, but it's checks only one column and not a matrix:

=INDEX(A$11:A$13, AGGREGATE(15, 6, ROW($1:$3)*SIGN(MATCH("*"&A$11:A$13&"*", B2, 0)), 1))

In simple words, I want to compute car manufacturer by product name.

解决方案

This formula will work, but it is quite long and making adding to the matrix Will only add to the length:

=INDEX($A$11:$A$13, IFERROR(AGGREGATE(15, 6, ROW($1:$3)*SIGN(MATCH("*"&A$11:A$13&"*", A2, 0)), 1),IFERROR(AGGREGATE(15, 6, ROW($1:$3)*SIGN(MATCH("*"&$B$11:$B$13&"*", A2, 0)), 1),IFERROR(AGGREGATE(15, 6, ROW($1:$3)*SIGN(MATCH("*"&$C$11:$C$13&"*", A2, 0)), 1),IFERROR(AGGREGATE(15, 6, ROW($1:$3)*SIGN(MATCH("*"&$D$11:$D$13&"*", A2, 0)), 1),0)))))

It basically keeps looking column by column till it finds an answer that works. As said if more models are wanted new, iferror formulas will need to be added for every column in the data matrix.

A quicker shorter method would be a UDF:

Function FINDINSTRING(Srch, rng) As String
Dim strArr() As String
Dim findArr()
Dim i&, j&, k&

findArr = rng.Value

strArr = Split(Srch, " ")


For i = LBound(strArr) To UBound(strArr)
    For j = LBound(findArr, 1) To UBound(findArr, 1)
        For k = LBound(findArr, 2) To UBound(findArr, 2)
            If UCase(strArr(i)) = UCase(findArr(j, k)) Then
                FINDINSTRING = findArr(j, 1)
                Exit Function
            End If
        Next k
    Next j
Next i

FINDINSTRING = "#N/A"

End Function

Which when placed in a module attached to the workbook:

From Excel hit Alt-F11. In that window goto Insert ==> Module. Into that module paste the above code.

Here is a better explanation with pictures.

It can be called directly from the worksheet. In B2 put:

=FINDINSTRING(A2,$A$11:$D$13)

Then it does not matter the size of the data matrix.

这篇关于Excel:查找包含在字符串中的矩阵单元格,并返回相同的行但不同的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆