|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub qs()
Dim arr, i, dic
Set dic = CreateObject("scripting.dictionary")
arr = Sheet1.[a1].CurrentRegion.Value
ReDim brr(1 To UBound(arr), 1 To 100)
For i = 2 To UBound(arr)
s = arr(i, 3)
If Not dic.exists(s) Then
m = m + 1
dic(s) = m
brr(m, 1) = s: brr(m, 2) = 1
brr(m, 3) = arr(i, 5)
Else
rw = dic(s)
brr(rw, 2) = brr(rw, 2) + 1
For j = 4 To 100
If brr(rw, j) = Empty Then
brr(rw, j) = arr(i, 5)
If ma <= j Then
ma = j
End If
Exit For
End If
Next
End If
Next
ReDim crr(1 To 2, 1 To 2)
crr(1, 1) = "班级": crr(1, 2) = "合计"
crr(2, 2) = Application.Sum(Application.Index(brr, 0, 2))
With Sheet2
.[a1].Resize(2, 2) = crr
.[a3].Resize(m, ma) = brr
End With
'目标表2
ReDim drr(1 To UBound(arr), 1 To 7)
x = m
m = 0
For i = 1 To x
m = m + 1
drr(m, 1) = brr(i, 1): drr(m, 2) = brr(i, 2)
cl = 2
For j = 3 To ma
If brr(i, j) <> Empty Then
cl = cl + 1
If j Mod 8 = 0 Then
m = m + 1
cl = 3
End If
If cl Mod 8 = 0 Then
cl = 3
End If
drr(m, cl) = brr(i, j)
Else
Exit For
End If
Next
Next
With Sheet3
ReDim Err(1 To 2, 1 To 7)
Err(1, 1) = "班级": Err(1, 2) = "人数": Err(1, 3) = "姓名": Err(2, 1) = "合计": Err(2, 2) = crr(2, 2)
For i = 1 To 5
Err(2, i + 2) = i
Next
.[a1].Resize(2, 7) = Err
.[a3].Resize(m, 7) = drr
End With
'目标表3
Dim frr
frr = Application.WorksheetFunction.Transpose(brr)
ReDim grr(1 To ma + 2, 1 To 1)
grr(1, 1) = "合计": grr(2, 1) = crr(2, 2)
For i = 1 To ma
grr(i + 2, 1) = i
Next
With Sheet4
.[a3].Resize(ma, 1) = grr
.[b3].Resize(ma, x) = frr
End With
Set dic = Nothing
End Sub
|
|