Excel高手,帮帮忙吧
来源:百度知道 编辑:UC知道 时间:2024/05/22 03:58:41
意思就是原来是
1----×××
1----***
2--%%%
2--¥¥¥
2---&&&
2---%%%
有没有啥公式可以运行后变成,并且把原来各行中相同的内容只显示一条
1--×××;***
2---%%%;¥¥¥;&&&
假设原始两列数据在A,B两列,在C列输入想集计的对象,你的例子中就是1,2,3。如果A列数据很多,可以筛选出来。
然后alt+F11,拷贝下面的代码,运行宏就可以在D列输出你要的结果。
Sub DataGather()
Dim cl1, cl2, cl3, cl4
For Each cl1 In Range("C:C").Cells
Set cl2 = Cells(cl1.Row, cl1.Column + 1)
If Trim(cl1.Value) = "" Then Exit Sub
cl2.Value = ""
For Each cl3 In Range("A:A").Cells
Set cl4 = Cells(cl3.Row, cl3.Column + 1)
If Trim(cl3.Value) = "" Then Exit For
If Trim(cl1.Value) = Trim(cl3.Value) Then
If cl2.Value = "" Then
cl2.Value = cl4.Value
Else
cl2.Value = cl2.Value & ";" & cl4.Value
End If
End If
Next
Next
End Sub
1,设置自动筛选
2,筛选1,复制筛选出来的结果-到空白处-右键-选择性粘贴-转置
选中数据区域,点击数据-数据透视表和数据透视图,点击完成,然后要把你需要单独显示