原帖由 蓝桥玄霜 于 2011-6-7 12:21 发表
Sub yy()
Dim i&, j&, Myr&, Myr1%, Arr, Arr1
Dim d, k, t, d1, k1, t1, x$, nm$, rq, col%, n%
Set d = CreateObject("Scripting.Dictionary")
Set d1 = CreateObject("Scripting.Dictionary")
Application.S ...
看了蓝老师的代码没有看懂,我用字典嵌套写了一个,请蓝老师斧正:
Sub Macro1()
Dim arr, brr(), d As Object, ds As Object, dic As Object, k, t, ks, i&, j&, y%, m%, ld%, lc%, n%
Set d = CreateObject("scripting.dictionary")
Set ds = CreateObject("scripting.dictionary")
Set dic = CreateObject("scripting.dictionary")
arr = Range("B2:C" & Range("B65536").End(xlUp).Row)
y = Year(arr(1, 2))
m = Month(arr(1, 2))
ld = Day(DateSerial(y, m + 1, 0))
For i = 1 To UBound(arr)
If Not d.Exists(arr(i, 1)) Then Set d(arr(i, 1)) = CreateObject("scripting.dictionary")
d(arr(i, 1))(arr(i, 2)) = ""
ds(arr(i, 2)) = ""
dic(arr(i, 1)) = dic(arr(i, 1)) + 1
Next
k = d.keys
t = dic.items
ks = ds.keys
ReDim brr(d.Count - 1, 1 To 28)
For i = 0 To d.Count - 1
brr(i, 1) = k(i)
brr(i, 2) = t(i)
n = 2
For j = 0 To ds.Count - 1
If Not d(k(i)).Exists(ks(j)) Then
n = n + 1
brr(i, n) = ks(j)
lc = IIf(n > lc, n, lc)
End If
Next
Next
ActiveSheet.UsedRange.Offset(3, 12).ClearContents
[m4].Resize(ds.Count) = Application.Transpose(ds.keys)
[n4].Resize(d.Count, lc) = brr
End Sub
考勤表zg.rar
(17.68 KB, 下载次数: 72)
[ 本帖最后由 zhaogang1960 于 2011-6-7 17:04 编辑 ] |