1、excel 将A列相同的值对应的B列的单元格进行合并,并保留单元格内容说明:现在A列有许多单元格的值是相同的,现在需要将相同值对应的B列的单元格进行合并,如:A列 B列aa a1aa a2bb a3bb a4最后的结果为(a1/a2在一个单元格,a3/a4在一个单元格):A列 B列aa a1 a2bb a3 a4程序一:Sub合并单元格()Setx=CreateObject(scriptcontrol)x.Language=jscriptx.evalarr=newArray();functionaa(aa,bb)arraa=arraa+bb;functioncc()kk=typeofarr+,
2、;for(iinarr)kk+=i+,;returnkk;Fori=2Toa2.End(4).RowCallx.Run(aa,Cells(i,1).Value,Cells(i,2).Value)NextSety=x.eval(arr)Z=x.Run(cc)arr=Split(Z,)j=1Fori=1ToUBound(arr)Cells(j,3)=arr(i)Cells(j,4)=Replace(CallByName(y,arr(i),2),undefined,)Cells(j,5)=Replace(Cells(j,4),Chr(10)将逗号替换为换行符j=j+1NextEndSub程序二:Su
3、b by20113()K = 1: Columns(D:K).ClearContentsD1:E1.Value = A1:B1.ValueFor I = 1 To 24(1-24行,根据具体数据修改记录行数)If Cells(I, 1) = Cells(I + 1, 1) ThenCells(K, 5) = Cells(K, 5) & Cells(I + 1, 2)Cells(K, 4) = Cells(I + 1, 1)ElseK = K + 1Cells(K, 4) = Cells(I + 1, 1)Cells(K, 5) = Cells(K, 5) & Cells(I + 1, 2)End IfNextEnd Sub