如何将不同的列值连接到单个单元格?

时间:2017-02-26 08:32:39

标签: excel vba excel-vba

。 大家好,我需要你在这里的主题输入。 我打算在不同的列中组合或连接不同的值,以便在单个单元格中显示。

插图如下: Picture

1

没有宏可以做到这一点吗?

2 个答案:

答案 0 :(得分:3)

使用

=CONCATENATE("The name of the painter: ",A3,CHAR(10), "The Hobby: ", B3, CHAR(10), "Tool used: ", C3,CHAR(10),"Remuneration: ", D3)

答案 1 :(得分:0)

回答关于如何使用代码执行此操作的第二个问题:

Sub PopulateResultsToCell()
    Dim X As Long, MyArr As Variant, PrefixArr As Variant
    PrefixArr = Array("The name of the painter: ", "The Hobby: ", "Tool used: ", "Remuneration: ")
    MyArr = Application.Transpose(Application.Transpose(Range("A3:D3"))) '<-- Change this for the range to read
    For X = LBound(MyArr) To UBound(MyArr)
        MyArr(X) = PrefixArr(X - 1) & Trim(MyArr(X)) 'Note: Option base is zero but transposing creates a base 1 array hence the X minus 1
    Next
    Range("F3").Formula = Join(MyArr, vbLf) '<-- Change this for where to populate the result to
End Sub