我有一个数据库文件,其中包含来自不同班级的所有学生的数据。我希望excel通过将数据从数据库复制到新文件来制作类明智的文件......我正在使用下面提到的代码,这些代码工作完美,但它只处理数据直到G列,现在数据已经扩展到Z列并且它不工作给我运行时错误。
“Note Column B title Class” 即新保存文件的标题
Sub proSaveDateClasswise()
Range("I1").Value = "Class"
Columns("B:B").AdvancedFilter Action:=xlFilterCopy, copyToRange:=Columns( _
"I:I"), unique:=True
Range("J1").Value = "Class"
Dim cell As Range
Dim curPath As String
curPath = ActiveWorkbook.Path & "\Extracted Files\\"
If Len(Dir(curPath, vbDirectory)) = 0 Then
MkDir (curPath)
End If
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each cell In Range("I:I")
If cell.Value <> "Branch" And cell.Value <> "" Then
Range("J2").Value = cell.Value
Range("A:G").AdvancedFilter Action:=xlFilterCopy, _
criteriarange:=Range("J1:J2"), copyToRange:=Range("L:R"), unique:=False
Range(Range("L1:R1"), Range("L1:R1").End(xlDown)).Copy
Workbooks.Add
ActiveSheet.Paste
ActiveWorkbook.SaveAs Filename:=curPath & cell.Value & ".xlsx", _
FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWindow.Close
Range(Range("L1:R1"), Range("L1:R1").End(xlDown)).ClearContents
End If
Next cell
Columns("I:R").Delete
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub