Excel 在逗号分隔列表的所有项目前加一个常量值
我有两个专栏。我想连接ColumnA和ColumnB中的单元格,以获得ColumnD中所示的输出。我尝试了Excel 在逗号分隔列表的所有项目前加一个常量值,excel,excel-formula,excel-2007,excel-2010,vba,Excel,Excel Formula,Excel 2007,Excel 2010,Vba,我有两个专栏。我想连接ColumnA和ColumnB中的单元格,以获得ColumnD中所示的输出。我尝试了列A和列B,但列C中显示的输出与所需的输出不一致。我该如何解决这个问题 Input1 |Input2 |Output |Desired output ColumnA|ColumnB |ColumnC |ColumnD ----------------------------------------- A |1,2,3,4 |A1,2,3,4 |A1, A2, A3, A4
列A和列B
,但列C中显示的输出与所需的输出不一致。我该如何解决这个问题
Input1 |Input2 |Output |Desired output
ColumnA|ColumnB |ColumnC |ColumnD
-----------------------------------------
A |1,2,3,4 |A1,2,3,4 |A1, A2, A3, A4
B |5,3,6,7 |B5,3,6,7 |B5, B3, B6, B7
C |8,9 |C8,9 |C8, C9
D |10,11,45|D10,11,45|D10, D11, D45
你可以试试这样的
=A1 & SUBSTITUTE(B1;",";", " & A1)
此用户定义的函数适用于我:
Function prependToAllElements(prefix As String, commaSeparatedList As String) As String
Dim i As Long
Dim s() As String
s = Split(commaSeparatedList, ",")
For i = LBound(s) To UBound(s)
s(i) = prefix & s(i)
Next i
prependToAllElements = Join(s, ",")
End Function
单元格D1中的示例用法:
=prependToAllElements(A1,B1)
是否尝试将
列a和列B
作为单元格中的公式?还是在VBA中?你试过VBA吗?我对VBA不太熟悉,我的程序主要是在shell中…你试过将ColumnA&ColumnB
作为单元格中的公式吗?还是在VBA中?你试过VBA吗?我试过ColumnA和ColumnB作为公式。我尝试使用MID(B2,FIND(“,”,B2,1)+1,1)查找每个逗号旁边的值,但无法循环遍历字符串