简体   繁体   English

如何在Excel中合并多个列

[英]How to combine multiple columns in excel

I'm using this formula that combines up to 3 columns in excel: 我正在使用以下公式,该公式在excel中最多包含3列:

=INDIRECT("A"&ROUNDUP((ROW())/PRODUCT(COUNTA($B$1:$B$98),COUNTA($C$1:$C$98)),0))&" "&INDIRECT("B"&MOD(ROUNDUP((ROW())/COUNTA($C$1:$C$98),0)-1,COUNTA($B$1:$B$98))+1)&" "&INDIRECT("C"&MOD(ROUNDUP((ROW()),0)-1,COUNTA($C$1:$C$98))+1)

It will basically combine the content of three columns like this: 它将基本上合并如下三列的内容:

在此处输入图片说明

Works great with 3 columns, however, I tried modifying the formula to support a fourth column (and perhaps more), but it's not combining the words properly. 3列效果很好,但是,我尝试修改公式以支持第4列(也许还有更多列),但是没有正确组合单词。 I was wondering if someone could show me how to modify it to make it work with 4 and maybe more columns. 我想知道是否有人可以告诉我如何修改它以使其与4列或更多列一起使用。

Thanks! 谢谢!

If you break down the formula, you'll notice a pattern involving calls to INDIRECT, so removing the inner formulas for each column you have something like this: 如果分解公式,您会注意到涉及到对INDIRECT的调用的模式,因此删除每个列的内部公式,您将得到以下内容:

=INDIRECT("A"&XXX)
&" "&INDIRECT("B"&YYY)
&" "&INDIRECT("C"&ZZZ)

Where XXX , YYY , and ZZZ are the respective formulas for each column. 其中XXXYYYZZZ是每列的相应公式。 Therefore, all you need to do is append an additional &" "&INDIRECT("D"&TTT) where TTT is the formula for the new 4th column. 因此,您所需要做的就是附加一个额外的&" "&INDIRECT("D"&TTT) ,其中TTT是新的第四列的公式。

Extending my answer, the function you are looking for looks like this: 扩展我的答案,您正在寻找的功能如下所示:

=INDIRECT("A"&ROUNDUP((ROW())/PRODUCT(COUNTA($B$1:$B$98),COUNTA($C$1:$C$98),COUNTA($D$1:$D$98)),0))&" "&INDIRECT("B"&ROUNDUP((ROW())/PRODUCT(COUNTA($C$1:$C$98),COUNTA($D$1:$D$98)),0))&" "&INDIRECT("C"&MOD(ROUNDUP((ROW())/COUNTA($D$1:$D$98),0)-1,COUNTA($C$1:$C$98))+1)&" "&INDIRECT("D"&MOD(ROUNDUP((ROW()),0)-1,COUNTA($D$1:$D$98))+1)

Breaking it down, you'll notice that the last 3 INDIRECT calls are identical to your existing INDIRECT calls, except all the references are shifted by one character (ie, A became B, B became C and C became D). 分解一下,您会注意到最后3个INDIRECT调用与您现有的INDIRECT调用相同,除了所有引用都移动了一个字符(即A变为B,B变为C,C变为D)。 Now look at the new first INDIRECT call and compare it to the second one: 现在查看新的第一个INDIRECT调用,并将其与第二个调用进行比较:

INDIRECT("A"&ROUNDUP((ROW())/PRODUCT(COUNTA($B$1:$B$98),COUNTA($C$1:$C$98),COUNTA($D$1:$D$98)),0))
INDIRECT("B"&ROUNDUP((ROW())/PRODUCT(COUNTA($C$1:$C$98),COUNTA($D$1:$D$98)),0))

You should notice that they differ only in that the first line has an additional ,COUNTA($D$1:$D$98) code inside the PRODUCT function. 您应该注意到它们的不同之处仅在于第一行在PRODUCT函数内还有一个附加的,COUNTA($D$1:$D$98)代码。 Using these observations, you should be able to expand the formula to further columns, but as @Tim Biegeleisen said, you should look for a different approach if your intention is to expand the function. 使用这些观察结果,您应该可以将公式扩展到其他列,但是正如@Tim Biegeleisen所说,如果您打算扩展函数,则应该寻找其他方法。

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

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