This is my Virtual Basic Application Code from my excel spreadsheet,(You can download it, scroll down)
Sub MakeAbsence()
Dim template As Worksheet
Dim data As Worksheet
Dim output As Worksheet
Dim output_remain As Worksheet
Dim teacher_list As Worksheet
Set template = ThisWorkbook.Worksheets("Template")
Set data = ThisWorkbook.Worksheets("Template_Data")
Set teacher_list = ThisWorkbook.Worksheets("Template_teacher")
' Getting Teacher's Names
Dim teachers_range As Variant
teachers_range = teacher_list.Range("A2:A5") 'Any idea how to automate this?
' Loop Through Teacher
Dim teacher As Variant
For Each teacher In teachers_range
' Copy Template
template.Copy After:=Worksheets(Worksheets.Count)
Set output = ActiveSheet
output.Name = teacher
' Change Name
Dim teacher_range As Range
Set teacher_range = output.Range("A6").EntireRow.Find("[teacher]", LookIn:=xlValues)
teacher_range.Value = teacher
' Filtering data
data.Range("B1:D" & data.Cells(data.Rows.Count, "C").End(xlUp).Row).AutoFilter Field:=3, Criteria1:=teacher
' Copying Data
Dim data_range As Range
Set data_range = data.Range("B2:C" & data.Cells(data.Rows.Count, "C").End(xlUp).Row).SpecialCells(xlCellTypeVisible)
If Not data_range Is Nothing Then
' Copy the first 14 rows to the output worksheet
If data_range.Rows.Count > 14 Then
data_range.Resize(14).Offset(1, 0).Copy Destination:=output.Range("B8")
' Copy the remaining rows to a new worksheet
Dim remaining_data_range As Range
Set remaining_data_range = data_range.Resize(data_range.Rows.Count - 14).Offset(15, 0)
template.Copy After:=Worksheets(Worksheets.Count)
Set output_remain = ActiveSheet
output_remain.Name = teacher & "_2"
remaining_data_range.Copy Destination:=ActiveSheet.Range("B8")
Dim teacher_range_remain As Range
Set teacher_range_remain = output_remain.Range("A6").EntireRow.Find("[teacher]", LookIn:=xlValues)
teacher_range_remain.Value = teacher
Else
data_range.Offset(1, 0).Copy Destination:=output.Range("B8")
End If
End If
' delete filter
data.AutoFilterMode = False
Next teacher
End Sub
Why My first row doesnt get copied as well? And is there any way to automate this code?
' Getting Teacher's Names
Dim teachers_range As Variant
teachers_range = teacher_list.Range("A2:A5")
So anyone know where did Abigail Taylor went?
Here is the GDrive Link for the EXCEL FILES