简体   繁体   English

使用单元格中的字符数作为 Excel 公式标准

[英]Use number of characters in a cell as Excel formula criteria

I have three columns in a spreadsheet, and my goal is to combine the individual references (column B) where the customer is the same (column A) - but only up to a maximum of 20 characters.我在电子表格中有三列,我的目标是合并客户相同的各个参考(B 列)(A 列)——但最多只能包含 20 个字符。

In column E, I use the following formula to combine the references if the value in column A is the same as the cell above: =IF(A2<>A1,"Reference " & B2,E1 & " " & B2)在 E 列中,如果 A 列中的值与上面的单元格相同,我使用以下公式合并引用: =IF(A2<>A1,"Reference " & B2,E1 & " " & B2)

In column G, I use the following formula to only return the final concatenated value: =IF(A2<>A3,CONCATENATE("",E2,""),"")在 G 列中,我使用以下公式仅返回最终的连接值:=IF(A2<>A3,CONCATENATE("",E2,""),"")

However, I'm struggling to find a way to stop combining the references if the cell length contains more than 20 characters, and starting a new concatenation on the next line - like I've put in column I?但是,如果单元格长度包含超过 20 个字符,我正在努力寻找一种方法来停止组合引用,并在下一行开始新的串联 - 就像我在 I 列中放入的那样?

Thanks!谢谢!

电子表格

It seems you're not looking for a parsimonious spreadsheet.看来您不是在寻找简约的电子表格。 Thus, this is what I can think of:因此,这是我能想到的:

Next to column G, you may add this formula, beginning on row 2 :在 G 列旁边,您可以添加这个公式,从第 2 行开始

=IF(LEN(G3)>20,IF(LEN(E2)>20,"",E2),IF(G2="","","Reference "&B2))

Column H (or I, as you wish) will have a 3-step IF statement: H 列(或 I,如您所愿)将有一个 3 步 IF 语句:

  1. If the length of the FOLLOWING string on column G is greater than 20, then copy the value on E2;如果 G 列的 FOLLOWING 字符串的长度大于 20,则复制 E2 上的值;
  2. But, if the value on E2 is longer than 20 characters, then return an empty cell;但是,如果 E2 上的值超过 20 个字符,则返回一个空单元格;
  3. Finally, if G3 has less than 20 characters AND provided G2 is NOT empty, then return "Reference" + whatever value is on B2.最后,如果 G3 少于 20 个字符且 G2 不为空,则返回“Reference”+ B2 上的任何值。 If G2 is empty, then return an empty cell ("").如果 G2 为空,则返回一个空单元格 ("")。

Thanks to the person who brought the image into the answer.感谢将图像带入答案的人。 I had to refresh it and that made it unavailable again, shamefully.我不得不刷新它,这使它再次不可用,可耻。

This is what it looks like:这是它的样子:

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

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