excel如何连接许多字符串中间并用英文逗号隔开?如果是用&的话一个一个连接太麻烦!

批次码 进货数量 序列码

150430 8 150430-001,150430-001,150430-001

150430 6

150430 6

150430 3
如上图所示,序列码为:批次码&“-”&“序列编号”。序列编号从1开始,自动加1,加到进货数量为止。怎么用公式实现,下面有不同的货物,不同的进货数量,手动太麻烦,求高人指导公式,一拉即可!

第1个回答  推荐于2016-01-01

用VBA的话会非常快

Sub test()
Dim s, X, m, i
s = Range("A65536").End(xlUp).Row
For i = 2 To s
    m = ""
    For X = 1 To Cells(i, 2)
       m = m & Cells(i, 1) & Format(X, "-000") & ","
    Next X
m = Left(m, Len(m) - 1)
Cells(i, 3) = m
Next i
End Sub

本回答被提问者采纳
第2个回答  2015-05-04
用自定义函数。
1)插入一个模块,输入代码如下:
Function GetReptString(strTitle As String, intRept As Integer) As String
Dim I As Integer
For I = 1 To intRept
GetReptString = GetReptString & strTitle & "-" & Format(I, "000")
If I < intRept Then GetReptString = GetReptString & ","
Next
End Function=GetReptString(A2,B2)
2)如A2=150430,B2=8,C2=GetReptString(A2,B2)本回答被网友采纳
相似回答