|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Option Base 1
Sub TEST()
Dim Arr
Dim Dict_Count As Integer
Dim d As Object
Dim New_Table() As String
Set Dict = CreateObject("scripting.dictionary")
Sheets("数据表").Activate
Row_Count = Cells(Rows.Count, 1).End(3).Row
Read_Area = "A2:C" & Trim(Row_Count)
Arr = Range(Read_Area)
Sheets("生成合并表").Activate
For i = 1 To UBound(Arr)
If Not Dict.exists(Arr(i, 1) & Arr(i, 2)) Then
m = 1
ReDim brr(1 To m)
Else
brr = Dict(Arr(i, 1) & Arr(i, 2))
m = UBound(brr) + 1
ReDim Preserve brr(1 To m)
End If
Dict(Arr(i, 1) & Arr(i, 2)) = brr
Next
K = Dict.Keys
Dict_Count = Dict.Count
ReDim New_Table(Dict_Count, 3)
For i = 0 To Dict.Count - 1
Key = K(i)
Pos = InStr(1, Key, "专业") + 1
ZY = Mid(Key, 1, Pos)
BJ = Mid(Key, Pos + 1, 100)
String_Tmp = ""
Count = 0
For j = 1 To UBound(Arr)
ZY1 = Arr(j, 1)
BJ1 = Arr(j, 2)
Stud_Name = Arr(j, 3)
If Count = 0 And ZY = ZY1 And BJ = BJ1 Then
Count = Count + 1
String_Tmp = Stud_Name & "、"
ElseIf Count > 0 And ZY = ZY1 And BJ = BJ1 Then
Count = Count + 1
String_Tmp = String_Tmp & Stud_Name & "、"
End If
Next
New_Table(i + 1, 1) = ZY
New_Table(i + 1, 2) = BJ
New_Table(i + 1, 3) = String_Tmp
String_Tmp_Len = Len(New_Table(i + 1, 3))
New_Table(i + 1, 3) = Mid(New_Table(i + 1, 3), 1, String_Tmp_Len - 1)
Next
Write_Area = "A2:C" & Trim(Dict_Count + 1)
Range(Write_Area) = New_Table
End Sub |
|