如何根据Excel中的其他单元格内容为一个单元格创建文本内容?

时间:2015-04-06 17:55:27

标签: excel vba excel-vba excel-formula

首先,我想说我已经在SO上搜索了这个问题,我发现了一些与我类似的问题,但是他们更多地处理数字而不是文本。

另一件事是,我不确定我想要做什么需要公式或VBA,所以我认为询问它会帮助我理解。

我需要做的是:我有一个excel电子表格,其中每一行(产品)都有许多包含文本(规范)的列。我需要添加一个新列,它将是产品的描述,它应该包含一些预制文本和一些来自其他列的文本。

其中一个描述的例子:

This item has a weight of (value of cell B12) and can be found in the following colors: (value of cell D12). It can be used for (value of cell E12) and has a price of (value of cell F12)

实现类似目标的最佳方法是什么?公式? VBA?如果可能的话,任何具体的例子都会很棒!

3 个答案:

答案 0 :(得分:2)

这应该是您正在寻找的:

=CONCATENATE("This item has a weight of ", B12, "and can be found in the following colors", D12,". It can be used for ", E12, "and has a price of ", F12)

您只是使用连接函数将这些单元格的值添加到字符串中。字符串的任何部分都应该在引号中,并且只要您想要包含另一个单元格,只需关闭当前引号,添加逗号,空格,然后再添加另一个逗号。然后,您可以使用括号关闭串联或启动另一个字符串。

答案 1 :(得分:2)

除了Concatenate之外,您还可以使用引号和逗号。

您可以将其输入地址栏:

="This item has a weight of " & B12 & " and can be found in the following colors" & D12 ". It can be used for " & E12 

...等。只需将不变的文字放在引号中,用“&”分隔即可并把细胞参考。另外请记住,如果要向上/向下拖动该公式,可以使用锚点(锚点是单元格引用中的$,即$ B $ 12)。

答案 2 :(得分:2)

您可以使用concatenate function来实现此目的:

enter image description here

您可以将此公式放在 G2 中,然后复制并向下拖动。

=CONCATENATE("This item has a weight of ", B2, " and can be found in the following colors ", D2,". It can be used for ",E2, " and has a price of  ", F2,".")



你去吧。