|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub test1() '个人理解,完成1、2 ; 第3汇总不参与。
- Dim vData, vResult(), Dict As Object, Sht As Worksheet
- Dim i As Long, j As Long, posRow As Long, s As String
- Dim titleRow As Long, splitCol As Long
- titleRow = 4 '标题所在 行
- splitCol = 14 '拆分依据 列
-
- DoApp False
-
- For Each Sht In Worksheets
- If Sht.Index > 3 Then Sht.Delete
- Next
-
- Set Sht = Worksheets("目录")
- Sht.Range("A1").CurrentRegion.Columns(1).Resize(, 2).Offset(1).Clear
-
- Set Dict = CreateObject("Scripting.Dictionary")
-
- With Worksheets("基础数据")
- vData = .Range("A1", .Range("A4").CurrentRegion)
- End With
-
- ReDim vTemp(1 To UBound(vData), 1 To UBound(vData, 2)) ' As String
- For j = 1 To UBound(vData, 2)
- For i = 1 To titleRow
- vTemp(i, j) = vData(i, j)
- Next
- Next
- For i = titleRow + 1 To UBound(vData)
- If Not Dict.Exists(vData(i, splitCol)) Then Dict(vData(i, splitCol)) = Dict.Count + 1
- Next
- ReDim vResult(1 To Dict.Count, 1 To 2)
- For i = 1 To Dict.Count
- vResult(i, 1) = titleRow
- vResult(i, 2) = vTemp
- Next
- For i = titleRow + 1 To UBound(vData)
- posRow = Dict(vData(i, splitCol))
- vResult(posRow, 1) = vResult(posRow, 1) + 1
- For j = 1 To UBound(vData, 2)
- vResult(posRow, 2)(vResult(posRow, 1), j) = vData(i, j)
- Next
- Next
- For i = 1 To Dict.Count
- s = vResult(i, 2)(titleRow + 1, splitCol)
- With Worksheets.Add(After:=Worksheets(Worksheets.Count))
- .Name = s
- .Range("A1").Resize(vResult(i, 1), UBound(vData, 2)) = vResult(i, 2)
- .Hyperlinks.Add .Cells(1, 1), "", "'" & Sht.Name & "'!A1", "单击返回目录", "返回目录"
- End With
- With Sht
- .Cells(i + 1, 1) = i
- .Hyperlinks.Add .Cells(i + 1, 2), "", "'" & s & "'!A1", "单击可跳转到该工作表", s
- End With
- Next
- Sht.Activate
- Set Sht = Nothing
- Set Dict = Nothing
- DoApp
- Beep
- End Sub
- Function DoApp(Optional b As Boolean = True)
- With Application
- .ScreenUpdating = b
- .DisplayAlerts = b
- .Calculation = -b * 30 - 4135
- End With
- End Function
复制代码 |
评分
-
1
查看全部评分
-
|