本代码是针对书《别怕,Excel_VBA其实很简单》示例文件_ExcelHome\第4章\4.7.7 批量对数据进行分类.xls 的练习,不同于书本中的代码
Sub test()
Dim i As Long
Dim rng As Range
Dim classname As String
Dim optype As String
Dim shtindex As Integer
Dim sht As Worksheet
i = 2
optype = "clearData" 'fillData,clearData
classname = Cells(i, "C").Value
Application.ScreenUpdating = False
If optype = "fillData" Then
Do While classname <> ""
Set rng = Worksheets(classname).Range("A65536").End(xlUp).Offset(1, 0)
Cells(i, "A").Resize(1, 7).Copy rng
i = i + 1
classname = Cells(i, "C").Value
Loop
ElseIf optype = "clearData" Then
For Each sht In Worksheets
If sht.Name <> "成绩表" And sht.Name <> "版权声明" Then
sht.Range("A2:G65536").ClearContents
End If
Next
End If
Application.ScreenUpdating = True
End Sub