|
- Sub 测试()
- Dim i%, j%, k%, arr, brr
- Dim rng As Range, sht As Worksheet
- Dim dic As Object, key, keys
- Set dic = CreateObject("scripting.dictionary")
- Set rng = Sheet1.Range("A1:J2")
- arr = Sheet1.Range("A3:J" & Sheet1.Cells(Rows.Count, "B").End(xlUp).Row)
- ReDim brr(1 To 100, 1 To 10)
- For i = LBound(arr) To UBound(arr)
- key = arr(i, 3)
- If Not dic.Exists(key) Then
- k = 0
- For j = 1 To 10
- brr(1, j) = arr(i, j)
- Next
- dic(key) = brr
- Else
- brr = dic(key)
- k = k + 1
- For j = 1 To 10
- brr(k + 1, j) = arr(i, j)
- Next
- dic(key) = brr
- End If
- Next
- keys = dic.keys
- For i = LBound(keys) To UBound(keys)
- key = keys(i)
- brr = dic(key)
- Set sht = Sheets.Add
- sht.Name = key
- sht.Range("A1") = rng.Copy
- sht.Range("A1").PasteSpecial Paste:=xlPasteAll, Operation:=xlPasteSpecialOperationNone, SkipBlanks:=False, Transpose:=False
- sht.Range("A2") = "班级:"
- sht.Range("B2") = key
- sht.Range("H2") = "班主任:"
- sht.Range("I2") = 班主任(Sheets("班主任"), key)
- sht.Range("A4").Resize(UBound(brr), 10) = brr
- sht.Columns(3).Delete
- Next
- End Sub
- Function 班主任(sht As Worksheet, key)
- Dim arr
- arr = sht.Range("A1").CurrentRegion
- For i = 2 To UBound(arr)
- If arr(i, 1) = key Then
- 班主任 = arr(i, 2)
- End If
- Next
- End Function
复制代码 |
评分
-
1
查看全部评分
-
|