|
- Option Explicit
- Sub byz()
-
- Rem 定义行数i/h,列数x,计数器j/k/y
- Dim i, j, k, h, x, y
- Dim zb As Range
- Dim w As Worksheet, w1 As Worksheet
- Set w = Worksheets("总表")
- Rem 总表分类辅助区域
- For i = 3 To 16 Step 1
-
- k = 1
-
- Do While w.Cells(k, 10) <> w.Cells(i, 5) And w.Cells(k, 10) <> ""
-
- k = k + 1
-
- Loop
-
- If w.Cells(k, 10) = "" Then
-
- w.Cells(k, 10) = w.Cells(i, 5)
- j = j + 1
-
- End If
-
- Next i
-
- Rem 创建子表
- For h = 1 To j Step 1
-
- Set w1 = Worksheets.Add
- w1.Name = w.Cells(h, 10)
- Set zb = Range(w1.Cells(1, 1), w1.Cells(1, 8))
- Rem 合并表头
- zb.Select
- Selection.Merge
- With zb
- .Value = w1.Name
- .Font.Size = 14
- .Font.Bold = True
- .Font.Name = "宋体"
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
-
- For x = 1 To 8 Step 1
-
- w.Cells(2, x).Copy
- w1.Cells(2, x).PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
- Application.CutCopyMode = False
-
- Next x
- Rem 子表数据拆分
- y = 3
- For i = 3 To 16 Step 1
-
- If w.Cells(i, 5) = w1.Name Then
-
- For x = 1 To 8 Step 1
-
- w.Cells(i, x).Copy
- w1.Cells(y, x).PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
- Application.CutCopyMode = False
-
- Next x
-
- y = y + 1
-
- End If
-
- Next i
-
- Next h
-
- Rem 删除辅助区域
- Range(w.Cells(1, 10), w.Cells(j, 10)).Clear
-
- End Sub
复制代码
|
|