简体   繁体   English

将多列合并到Excel中的一个单元格

[英]Combine several columns into one cell in Excel

I have a situation where I have 123 columns of data and out of those 123 colums, only up to 6 of them will be poplated with data. 我遇到的情况是我有123列数据,而在这123个列中,只有多达6列会填充数据。 I need to collect all the fields that do have data and put them into one cell. 我需要收集所有具有数据的字段并将它们放入一个单元格中。

I found this article, How to merge rows in a column into one cell in excel? 我找到了这篇文章, 如何将列中的行合并到Excel中的一个单元格中? , on stackoverflow but it still is not quite what I am looking for and I could not get the =transpose solution to work as suggested at the bottom of the thread. 在stackoverflow上,但仍然不是我想要的东西,并且我无法使= transpose解决方案按照线程底部的建议工作。 I found a 3rd party solution that was a plugin for Excel but it is only for Windows and I have Office for Mac. 我找到了第三方解决方案,该解决方案是Excel的插件,但仅适用于Windows,并且我具有Office for Mac。

So I desperately need to know how to do this. 因此,我非常需要知道如何执行此操作。 I'am not showing 123 columns but I think you get the idea. 我没有显示123列,但我认为您明白了。 http://grab.by/BwDu http://grab.by/BwDu

=concatenate(text,text,text...) is not an option because even if I wanted to put all 123 fields in here i am still faced with the problem of the formula putting in a space or comma in place of a blank field. = concatenate(text,text,text ...)不是一个选择,因为即使我想将所有123个字段都放在这里,我仍然面临着用空格或逗号代替空白字段的公式问题。

The ConcatenateRange function at the link you posted seems to accomplish what you want. 您发布的链接上的ConcatenateRange函数似乎完成了您想要的。

If you prefer a formula, this works for your example data: 如果您喜欢公式,则适用于您的示例数据:

=SUBSTITUTE(
  TRIM(
   B1&" "&C1&" "&D1&" "&E1&" "&F1&" "&G1&" "&H1&" "&I1&" "&J1&" "&
   K1&" "&L1&" "&M1&" "&N1&" "&O1&" "&P1&" "&Q1&" "&R1&" "&S1
  ),
  " ",
  ","
 )

Output: 输出:

cat,bird,dog,mouse,horse,elephant,chimp,lion,sloth,zebra,geraf,snake,grasshopper

This formula concatenates the data with spaces. 此公式将数据与空格连接在一起。 TRIM changes multiple spaces to single spaces, and SUBSTITUTE replaces all the spaces with commas. TRIM将多个空格更改为单个空格,而SUBSTITUTE用逗号替换所有空格。

To reach 123 columns, you'll simply need to continue adding cells. 要达到123列,您只需要继续添加单元格即可。

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

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