|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 zhaogang1960 于 2013-6-30 00:42 编辑
学不完用不尽 发表于 2013-6-29 22:32
经常看到赵版主您的杰作,谢天谢地,终于得到您的一个答复!感到荣幸!
有个小小的问题,就是要对被合并 ...
- Sub Macro1()
- Dim p$, f$, arr, brr(1 To 60000, 1 To 256), d As Object, ds As Object
- Dim i&, j, m&, n&, r, y$, sh As Worksheet
- Set d = CreateObject("scripting.dictionary")
- Set ds = CreateObject("scripting.dictionary")
- ds("单位") = 1
- ds("年") = 2
- n = 2
- p = ThisWorkbook.Path & ""
- f = Dir(p & "*.xls")
- Application.ScreenUpdating = False
- Do While f <> ""
- If f <> ThisWorkbook.Name Then
- With GetObject(p & f)
- For Each sh In .Sheets
- arr = sh.[a1].CurrentRegion
- If IsArray(arr) Then
- y = Left$(f, 4)
- For j = 2 To UBound(arr, 2)
- If Not ds.Exists(arr(1, j)) Then
- n = n + 1
- ds(arr(1, j)) = n
- End If
- Next
- For i = 2 To UBound(arr)
- s = arr(i, 1) & Chr(9) & y & Chr(9) & arr(i, 2) & Chr(9) & arr(i, 3)
- r = d(s)
- If r = "" Then
- m = m + 1
- d(s) = m
- brr(m, 1) = arr(i, 1)
- brr(m, 2) = y
- For j = 2 To UBound(arr, 2)
- brr(m, ds(arr(1, j))) = arr(i, j)
- Next
- Else
- For j = 4 To UBound(arr, 2)
- brr(r, ds(arr(1, j))) = brr(r, ds(arr(1, j))) + arr(i, j)
- Next
- End If
- Next
- End If
- Next
- .Close False
- End With
- End If
- f = Dir
- Loop
- Cells.ClearContents
- [a1].Resize(, n) = ds.keys
- [a2].Resize(m, n) = brr
- Application.ScreenUpdating = True
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|