|
这个用宏来做很容易实现。
代码如下——
- Option Explicit
- Sub 生成子表()
- Dim wst As Worksheet, dic As Object, k As Range, arr, i%
- Application.ScreenUpdating = False
- '删除所有子表
- Application.DisplayAlerts = False
- For Each wst In ThisWorkbook.Sheets
- If wst.Name <> "花名册总表" Then wst.Delete
- Next
- Application.DisplayAlerts = True
- Set dic = CreateObject("Scripting.Dictionary")
- With Sheets("花名册总表")
- '提取支部列表
- For Each k In .Range("C5:C" & .[A65536].End(xlUp).Row)
- If k <> "" And Not dic.Exists(k.Value) Then dic.Add k.Value, ""
- Next k
- arr = dic.keys
- '生成支部各表
- For i = 0 To dic.Count - 1
- Set wst = Worksheets.Add(after:=Sheets(Worksheets.Count))
- wst.Name = arr(i)
- .[IV1] = "支部名称"
- .[IV2] = arr(i)
- .[A5].CurrentRegion.AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=.[IV1:IV2], CopyToRange:=wst.Cells(1)
- Next i
- End With
- Set wst = Nothing
- Set dic = Nothing
- Application.ScreenUpdating = True
- End Sub
复制代码
|
|