简体   繁体   English

根据行和列的交集值返回值

[英]Return values, based on value of an intersection of a row and column

I want to return a label(s) based on an intersection of a Row and Column equal to "Yes". 我想基于等于“是”的行和列的交集返回一个标签。

            |       Location       |    
ID | Tool   | Wall | Bin | Toolbox | Count   
---+--------+------+-----+---------+-------
1. | Axe    | YES  |     |         | 1  
2. | Hammer |      |     | YES     | 5      
3. | Pliers |      |     | YES     | 2      
4. | Nails  |      | YES |         | 500        
5. | Hoe    | YES  |     |         | 2  
6. | Screws |      | YES |         | 200    
7. | Saw    | YES  |     |         | 3

What's in Toolbox? 工具箱中有什么? (Results wanted) (想要的结果)

Axe,Wall, 1 
Hammer, Toolbox, 5
Pliers,Toolbox, 2
Nails,Bin, 500
Hoe, Wall, 2
Screws, Bin, 200
Saw, Wall, 3

I also want to be able add Tools and Locations? 我还希望能够添加工具和位置?

Without using VBA, this is going to be a bit of a pain, but workable if you don't mind helper columns. 如果不使用VBA,这会有些麻烦,但是如果您不介意helper列,则可以使用。 I don't advise trying to do this in a single Array Formula, because text strings are hard to work with in Array formulas. 我不建议尝试在单个数组公式中执行此操作,因为文本字符串很难在数组公式中使用。 That is - if you have an array of numbers, you can turn that into a single result a lot of ways (MIN, MAX, AVERAGE, SUM, etc.). 也就是说-如果您有一组数字,则可以通过多种方式(最小,最大,平均,总和等)将其转换为单个结果。 However with an array of strings, it's harder to work with. 但是,如果使用字符串数组,则很难使用。 Particularly, there's no easy way to concatenate an array of strings. 特别是,没有简单的方法来连接字符串数组。

So instead, use a helper column. 因此,请使用帮助程序列。 Assume column A = toolname, column B = a check for being on the wall, column C = a check for being in the bin, column D for being in the toolbox, and column E for the number available. 假设A列=工具名称,B列=检查在墙上,C列=检查在箱中,D列显示在工具箱中,E列显示可用编号。

FORMATTING SIDE NOTE 格式说明

First, I will say that I recommend you use TRUE/FALSE instead of "yes"/"no". 首先,我会建议您使用TRUE / FALSE,而不是“ yes” /“ no”。 This is because it is easier to use TRUE / FALSE within Excel formulas. 这是因为在Excel公式中更容易使用TRUE / FALSE。 For example, if you want to add A1 + A2 when A3 = "yes", you can do so like this: 例如,如果要在A3 =“ yes”时添加A1 + A2,则可以这样进行:

=IF(A3="yes",A1+A2)

But if you want to check whether A3 = TRUE, this is simplified: 但是,如果要检查A3 = TRUE,可以简化以下操作:

=IF(A3,A1+A2)

Here, we didn't need to hardcode "yes", because A3 itself will either be TRUE or FALSE. 在这里,我们不需要对“是”进行硬编码,因为A3本身将为TRUE或FALSE。 Also consider if you want to make a cell "yes" if A3 > 5, and otherwise be "no". 还考虑如果A3> 5,是否要使单元格为“是”,否则为“否”。 You could do it like this: 您可以这样做:

=IF(A3>5,"yes","no)

Or, if you used TRUE/FALSE, you could simply use: 或者,如果您使用TRUE / FALSE,则可以简单地使用:

=A3>5

However, I'll assume that you keep the formatting you currently have (I would also recommend you just have a single cell that says either "toolbox"/"bin" etc., instead of 4 columns where 1 says "yes", but we'll also assume that this needs to be this way). 但是,我假设您保持当前的格式(我也建议您仅使用一个单元格,其中显示“ toolbox” /“ bin”等,而不是4列,其中1表示“ yes”,但是我们还假定这需要采用这种方式。

BACK TO YOUR QUESTION 返回您的问题

Put this in column F, in F2 for the first cell: 将其放在第一个单元格的F列中的F2中:

=Concatenate(A2," ",INDEX($B$1:$D$1,MATCH("yes",B2:D2,0))," ",E2)

Concatenate combines strings of text into a new single text string. 串联将文本字符串组合成新的单个文本字符串。 You could also use &; 您也可以使用&; like: A2 & " " etc., but with this many terms, this is likely easier to read. 例如:A2和“”等,但是由于有这么多术语,这很容易阅读。 Index looks at your header row 1, and returns the item from the first column which matches "yes" in the current row. 索引查看标题行1,并从第一列返回与当前行中“是”匹配的项目。

Then put the following in F3 and drag down: 然后将以下内容放到F3中并向下拖动:

=Concatenate(F2," ", A2," ",INDEX($B$1:$D$1,MATCH("yes",B2:D2,0))," ",E2)

This puts a space in between the line above and the current line. 这在上方的行和当前行之间放置了一个空格。 If instead you want to make each row appear after a line-break, use this: 相反,如果您想使每行显示在换行符之后,请使用以下命令:

=Concatenate(F2,CHAR(10), A2," ",INDEX($B$1:$D$1,MATCH("yes",B2:D2,0))," ",E2)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM