Excel多行自动合并问题
发布网友
发布时间:2022-11-02 16:54
我来回答
共2个回答
热心网友
时间:2023-10-24 05:01
1、在A列插入一列辅助列,然后在A2单元格输入以下数组公式,按Ctrl+Shift+Enter组合键结束,然后向下填充公式
=B2&IF(COUNTIFS(C3:C$7,C2,D3:D$7,D2)>0,","&INDEX(A3:A$7,MATCH(C2&D2,C3:C$7&D3:D$7,0)),"")
2、复制CD列到GH列,选择GH列,在“数据”选项下的“删除重复项”中,保留唯一值;
3、在F2单元格输入以下数组公式,按Ctrl+Shift+Enter组合键结束,然后向下填充公式
=INDEX(A:A,MATCH(G2&H2,C:C&D:D,0))
FGH即为需要的结果
详见附图
热心网友
时间:2023-10-24 05:01
Sub 合并()
Dim yye As Object, nRow%, Arr()
Set yye = CreateObject("Scripting.dictionary")
nRow = Range("a1").End(xlDown).Row
Arr = Range("a2:c" & nRow).Value
For i = 1 To nRow - 1
yye(Arr(i, 2) & "," & Arr(i, 3)) = yye(Arr(i, 2) & "," & Arr(i, 3)) & "," & Arr(i, 1)
Next
Range("e2:g" & yye.Count).ClearComments
R = 0
ar = yye.keys
For a = 0 To UBound(ar)
br = Split(ar(a), ",")
Range("e2").Offset(R) = br(0)
Range("f2").Offset(R) = br(1)
R = R + 1
Next
Range("g2").Resize(yye.Count).Value = WorksheetFunction.Transpose(Array(yye.items))
End Sub追问您的代码倒是方便,可以提的这个问题只是举例,实际上还有好多列的信息的,我又不会改代码,所以把这个运用到实际表格里面就不对了!