|
针对你的附件中的表,我试着编了一段代码,因为也是初学,可能会有很多不严谨的地方,仅做参考,不知道能否满足要求。- Sub zz()
- Dim m, n, r, i, str As String
- Dim ar, br(1 To 1000, 1 To 50)
- Dim d1 As Object, d2 As Object
- Set d1 = CreateObject("scripting.dictionary")
- Set d2 = CreateObject("scripting.dictionary")
- For Each sht In Sheets
- If sht.Name <> "汇总" Then
- n = n + 1
- d2(sht.Name) = n
- With sht
- r = .Cells(Rows.Count, 1).End(xlUp).Row
- ar = .Range("a2:b" & r)
- End With
- For i = 1 To UBound(ar)
- If Not d1.exists(ar(i, 1)) Then
- m = m + 1
- d1(ar(i, 1)) = m
- br(m, n) = ar(i, 2)
- Else
- br(d1(ar(i, 1)), n) = ar(i, 2)
- End If
- Next i
- End If
- Next
- Sheets("汇总").[a2].Resize(m, 1) = Application.Transpose(d1.keys())
- Sheets("汇总").[b1].Resize(1, n) = d2.keys()
- Sheets("汇总").[b2].Resize(m, n) = br
- End Sub
复制代码
|
评分
-
3
查看全部评分
-
|