|
Sub 数据整理()
Application.ScreenUpdating = False
Dim ar As Variant
Dim d As Object, dc As Object
Set d = CreateObject("scripting.dictionary")
Set dc = CreateObject("scripting.dictionary")
With Sheets("班级数据表")
r = .Cells(Rows.Count, 1).End(xlUp).Row
y = .Cells(2, Columns.Count).End(xlToLeft).Column
If r < 3 Or y < 3 Then MsgBox "班级数据表为空!": End
ar = .Range(.Cells(1, 1), .Cells(r, y + 1))
End With
For i = 3 To UBound(ar)
For j = 3 To UBound(ar, 2) - 1 Step 2
If ar(i, j) <> "" Then
If ar(i, j) <> "/" Then
If d(ar(i, j)) = "" Then
d(ar(i, j)) = ar(i, 1) & "|" & ar(2, j) & "|" & ar(i, j + 1)
Else
d(ar(i, j)) = d(ar(i, j)) & ";" & ar(i, 1) & "|" & ar(2, j) & "|" & ar(i, j + 1)
End If
End If
End If
Next j
Next i
ReDim br(1 To d.Count + 1, 1 To 330)
lh = 0
n = 1
br(n, 1) = "序号"
br(n, 2) = "姓名"
br(n, 3) = "号码"
For Each k In d.keys
n = n + 1
br(n, 1) = n
br(n, 2) = k
zf = d(k)
rr = Split(zf, ";")
x = 3
For i = 0 To UBound(rr)
zd = rr(i)
mr = Split(zd, "|")
For s = 0 To UBound(mr)
x = x + 1
br(n, x) = mr(s)
Next s
Next i
If x > lh Then
lh = x
Else
lh = lh
End If
Next k
rr = Array("班级", "课程", "课时")
For j = 4 To lh - 2 Step 3
w = j - 1
For s = 0 To UBound(rr)
w = w + 1
br(1, w) = rr(s)
Next s
Next j
With Sheets("sheet1")
.UsedRange.Borders.LineStyle = 0
.UsedRange.ClearContents
.[a1].Resize(n, lh) = br
.[a1].Resize(n, lh).Borders.LineStyle = 1
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|