excel表内,若A列相同数据,B列内容合并,以分号“;”隔开,如何实现?_百...
发布网友
发布时间:2024-09-28 13:27
我来回答
共2个回答
热心网友
时间:2024-10-15 05:43
需要用VBA来弄的话,扣
代码如下
Sub test()
Dim i As Long, jl As Long, ary, aryB, d As Object, st As String, t As Double
t = Timer
jl = [a1048576].End(3).Row
ary = Range("A2:B" & jl)
Set d = CreateObject("scripting.dictionary")
For i = LBound(ary) To UBound(ary)
d(ary(i, 1)) = ""
Next
aryB = d.keys
k = 1
For i = LBound(aryB) To UBound(aryB)
k = k + 1
Cells(k, "C") = aryB(i)
For j = LBound(ary) To UBound(ary)
If ary(j, 1) = aryB(i) Then
st = st & ary(j, 2) & ";"
End If
Next
Cells(k, "D") = Left(st, Len(st) - 1)
st = ""
Next
MsgBox "处理结束,共用时" & Timer - t & "秒"
End Sub
热心网友
时间:2024-10-15 05:50
参考我其他的回答
http://zhidao.baidu.com/link?url=aKnjv7gaqjjnhcL12XvFWDgL5GEzq2luK2xRGBATA4e_hsiyoxgizv2fk76YWpx_-VYj_Cu4cWIV1BYsKUZn1sTQQ957xUf4DDtyy0ruKZe
如有必须发样表