我们需要操作的是根据班级列,将花名册拆分为5个工作表,分别以班级名称命名工作表的名称。
在【插入】选项卡下面的【表格】组中找到【数据透视表】,单击,弹出创建数据透视表对话框,点击确定就可以。
2.生成数据透视表
依次双击生成的数据透视表中的计数项,就可以生成工作表。
4.通过录制宏的方式批量设置工作表格式。
录制后生成如下代码:
' 宏1 宏
Selection.RowHeight = 20
.HorizontalAlignment = xlCenter
.WrapText = False
.AddIndent = False
.ShrinkToFit = False
.MergeCells = False
With Selection.Font
.Size = 11
.Superscript = False
.OutlineFont = False
.Underline = xlUnderlineStyleNone
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
With Selection.Font
.Size = 12
.Superscript = False
.OutlineFont = False
.Underline = xlUnderlineStyleNone
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.ColorIndex = 0
.Weight = xlThin
With Selection.Borders(xlEdgeTop)
.ColorIndex = 0
.Weight = xlThin
With Selection.Borders(xlEdgeBottom)
.ColorIndex = 0
.Weight = xlThin
With Selection.Borders(xlEdgeRight)
.ColorIndex = 0
.Weight = xlThin
With Selection.Borders(xlInsideVertical)
.ColorIndex = 0
.Weight = xlThin
With Selection.Borders(xlInsideHorizontal)
.ColorIndex = 0
.Weight = xlThin
ActiveWindow.SmallScroll Down:=-9
ActiveCell.FormulaR1C1 = "1"
ActiveCell.FormulaR1C1 = "2"
Selection.AutoFill Destination:=Range("表2[序号]")
ActiveWindow.SmallScroll Down:=48
Sheets("Sheet3").Name = "高1班"
ActiveWindow.SmallScroll Down:=-84
在其他工作表中,大家需要操作的仅仅是将表2更改为新表的名称即可。最后的工作表重命名代码处如果大家对VBA有点基础的话可以做如下更改:
Sheets("Sheet3").Name = "高1班"
ActiveSheet.Name = Cells(2, 3)
如果大家需要获取本文档的演示文件,请关注我后私信【拆分工作表】获取。
