I'm trying to use a "nested For Next loop" for the first time. I would appreciate your help for the following problem. Below is my code. I apologize for its length but, I thought it might be needed in its entirety to understand the issue. I'm getting a Compile Error - Next without For.
Thanks in advance for your assistance.
Thanks in advance for your assistance.
Code:
Sub Create_JD_Workbooks()
'Get directory information and ECS requirement data.
Grp_ECS_Path = Sheets("JD Workbook Requirements").Cells(12, 6)
ECS_Template_Path = Sheets("JD Workbook Requirements").Cells(14, 6)
ECS_Save_Path = Sheets("JD Workbook Requirements").Cells(16, 6)
LstRowNo = Sheets("JD Workbook Requirements").Cells(20, 6)
Grp_ECS_Save_Dir = Sheets("JD Workbook Requirements").Cells(18, 6)
'CREATE ECS Files
Dim TotRows As Integer
Dim StartLine As Integer
Dim EndLine As Integer
Dim I As Integer
Dim CurrRow As Integer
Dim CurrRow2 As Integer
Workbooks("Create XYZ Job Description Workbooks_2.xlsm").Activate
TotRows = Sheets("All Job Properties").Cells(1, 1)
CurrRow = 2
Workbooks("Create XYZ Job Description Workbooks_2.xlsm").Activate
TotRows2 = Sheets("Pivot Table").Cells(1, 1)
CurrRow2 = 2
Workbooks("Create XYZ Job Description Workbooks_2.xlsm").Activate
TotRows3 = Sheets("Pivot Table Job Elements").Cells(1, 1)
CurrRow3 = 2
For I = 1 To TotRows
EECount = Sheets("Pivot Table").Cells(CurrRow2, 3)
StartLine = Sheets("Pivot Table").Cells(CurrRow2, 4)
EndLine = Sheets("Pivot Table").Cells(CurrRow2, 5)
Filename = Sheets("All Job Properties").Cells(CurrRow, 45)
Job_Title = Sheets("All Job Properties").Cells(CurrRow, 2)
Job_Code = Sheets("All Job Properties").Cells(CurrRow, 4)
Grade = Sheets("All Job Properties").Cells(CurrRow, 7)
Grade2 = Sheets("All Job Properties").Cells(CurrRow, 8)
Job_Family = Sheets("All Job Properties").Cells(CurrRow, 12)
Summary = Sheets("All Job Properties").Cells(CurrRow, 19)
FLSA = Sheets("All Job Properties").Cells(CurrRow, 23)
RowNo = Sheets("All Job Properties").Cells(CurrRow, 43)
GrpCtr = Sheets("All Job Properties").Cells(CurrRow, 44)
grpcounternext = Sheets("All Job Properties").Cells(CurrRow + 1, 44)
CS_Type = Sheets("All Job Properties").Cells(CurrRow, 46)
Education = Sheets("All Job Properties").Cells(CurrRow, 47)
Wksht_Job_Title = Sheets("All Job Properties").Cells(CurrRow, 49)
'******************************************************************************************
If GrpCtr = 1 Then
Workbooks.Open Filename:=Grp_ECS_Path & "" & "XYZ Group Job Desc Workbook.xlsx"
'Copy Job Title into Group Workbook
Windows("Create XYZ Job Description Workbooks_2.xlsm").Activate
Sheets("All Job Properties").Select
RangeArea = "B" & StartLine & ":B" & EndLine
Range(RangeArea).Select
Selection.Copy
Windows("XYZ Group Job Desc Workbook.xlsx").Activate
Sheets("Job Family").Select
Range("A2").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
'Copy Job Code into Group Workbook
Workbooks("Create XYZ Job Description Workbooks_2.xlsm").Activate
Sheets("All Job Properties").Select
RangeArea = "D" & StartLine & ":D" & EndLine
Range(RangeArea).Select
Selection.Copy
Windows("XYZ Group Job Desc Workbook.xlsx").Activate
Sheets("Job Family").Select
Range("B2").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
'Copy Grade into Group Workbook
Workbooks("Create XYZ Job Description Workbooks_2.xlsm").Activate
Sheets("All Job Properties").Select
RangeArea = "G" & StartLine & ":G" & EndLine
Range(RangeArea).Select
Selection.Copy
Windows("XYZ Group Job Desc Workbook.xlsx").Activate
Sheets("Job Family").Select
Range("C2").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
'Copy Management Level into Group Workbook
Workbooks("Create XYZ Job Description Workbooks_2.xlsm").Activate
Sheets("All Job Properties").Select
RangeArea = "H" & StartLine & ":H" & EndLine
Range(RangeArea).Select
Selection.Copy
Windows("XYZ Group Job Desc Workbook.xlsx").Activate
Sheets("Job Family").Select
Range("D2").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
'Copy FLSA into Group Workbook
Workbooks("Create XYZ Job Description Workbooks_2.xlsm").Activate
Sheets("All Job Properties").Select
RangeArea = "W" & StartLine & ":W" & EndLine
Range(RangeArea).Select
Selection.Copy
Windows("XYZ Group Job Desc Workbook.xlsx").Activate
Sheets("Job Family").Select
Range("E2").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
'Copy Job Summary into Group Workbook
Workbooks("Create XYZ Job Description Workbooks_2.xlsm").Activate
Sheets("All Job Properties").Select
RangeArea = "S" & StartLine & ":S" & EndLine
Range(RangeArea).Select
Selection.Copy
Windows("XYZ Group Job Desc Workbook.xlsx").Activate
Sheets("Job Family").Select
Range("F2").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
' Delete Unneeded Rows in Job Family Worksheet
Windows("XYZ Group Job Desc Workbook.xlsx").Activate
Sheets("Job Family").Select
RangeArea = "A" & (EECount + 2) & ":w10000"
Range(RangeArea).Select
Selection.Delete Shift:=xlUp
Range("A1").Select
'Sort by LNAME
Cells.Select
Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Range("A1").Select
CurrRow2 = CurrRow2 + 1
End If
'Individual Job Description
If CS_Type = 1 Then
Workbooks.Open Filename:=ECS_Template_Path & "\XYZ Job Description.xlsx"
'Enter Demographic information
Range("D4").Select
ActiveCell.FormulaR1C1 = Job_Title
Range("D6").Select
ActiveCell.FormulaR1C1 = Job_Code
Range("D8").Select
ActiveCell.FormulaR1C1 = Grade
Range("D10").Select
ActiveCell.FormulaR1C1 = Grade2
Range("D12").Select
ActiveCell.FormulaR1C1 = Job_Family
Range("D14").Select
ActiveCell.FormulaR1C1 = Summary
Range("D16").Select
ActiveCell.FormulaR1C1 = FLSA
Range("D18").Select
ActiveCell.FormulaR1C1 = Education
'******************************************************************************************
For I_2 = 1 To TotRows3
EECount3 = Sheets("Pivot Table Job Elements").Cells(CurrRow3, 4)
StartLine3 = Sheets("Pivot Table Job Elements").Cells(CurrRow3, 5)
EndLine3 = Sheets("Pivot Table Job Elements").Cells(CurrRow3, 6)
Job_Title_Elements = Sheets("Job Specific Essential Fun,4274").Cells(CurrRow3, 2)
Job_Code_Elements = Sheets("Job Specific Essential Fun,4274").Cells(CurrRow3, 3)
Job_Elements = Sheets("Job Specific Essential Fun,4274").Cells(CurrRow3, 11)
RowNo_Elements = Sheets("Job Specific Essential Fun,4274").Cells(CurrRow3, 43)
GrpCtr_Elements = Sheets("Job Specific Essential Fun,4274").Cells(CurrRow3, 44)
grpcounternext_Elements = Sheets("Job Specific Essential Fun,4274").Cells(CurrRow3 + 1, 44)
CS_Type_Elements = Sheets("Job Specific Essential Fun,4274").Cells(CurrRow3, 46)
Education = Sheets("Job Specific Essential Fun,4274").Cells(CurrRow3, 47)
'******************************************************************************************
'Copy Essential Job Elements into Job Description Worksheet23
Windows("Create XYZ Job Description Workbooks_2.xlsm").Activate
Sheets("Job Specific Essential Fun,4274").Select
RangeArea = "L" & StartLine3 & ":L" & EndLine3
Range(RangeArea).Select
Selection.Copy
Windows("XYZ Job Description.xlsx").Activate
Sheets("Name").Select
Range("D25").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Next I_2
'CurrRow3 = CurrRow + 1
'******************************************************************************************
'Copy Leadership Elements into Job Description Worksheet
If Grade2 = "Supervisor" Then
Sheets("Leadership Essential Elements").Select
RangeArea = "B2:B3"
Range(RangeArea).Select
Selection.Copy
Workbooks("XYZ Job Description.xlsx").Activate
Sheets("Name").Select
Range("D20").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Else
If Grade2 = "Coordinator" Then
Sheets("Leadership Essential Elements").Select
RangeArea = "B4:B6"
Range(RangeArea).Select
Selection.Copy
Workbooks("XYZ Job Description.xlsx").Activate
Sheets("Name").Select
Range("D20").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Else
If Grade2 = "Manager" Then
Sheets("Leadership Essential Elements").Select
RangeArea = "B7:B9"
Range(RangeArea).Select
Selection.Copy
Workbooks("XYZ Job Description.xlsx").Activate
Sheets("Name").Select
Range("D20").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Else
If Grade2 = "Senior Manager" Then
Sheets("Leadership Essential Elements").Select
RangeArea = "B10:B12"
Range(RangeArea).Select
Selection.Copy
Workbooks("XYZ Job Description.xlsx").Activate
Sheets("Name").Select
Range("D20").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Else
If Grade2 = "Director" Then
Sheets("Leadership Essential Elements").Select
RangeArea = "B13:B16"
Range(RangeArea).Select
Selection.Copy
Workbooks("XYZ Job Description.xlsx").Activate
Sheets("Name").Select
Range("D20").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Else
If Grade2 = "Executive Director" Then
Sheets("Leadership Essential Elements").Select
RangeArea = "B17:B20"
Range(RangeArea).Select
Selection.Copy
Workbooks("XYZ Job Description.xlsx").Activate
Sheets("Name").Select
Range("D20").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Else
If Grade2 = "Vice President" Then
Sheets("Leadership Essential Elements").Select
RangeArea = "B21:B24"
Range(RangeArea).Select
Selection.Copy
Workbooks("XYZ Job Description.xlsx").Activate
Sheets("Name").Select
Range("D20").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Else
Workbooks("XYZ Job Description.xlsx").Activate
Sheets("Name").Select
Rows("20:24").Select
Selection.Delete Shift:=xlUp
End If
'*****************************************************************************************
CurrRow3 = CurrRow + 1
'*****************************************************************************************
Workbooks("XYZ Job Description.xlsx").Activate
Sheets("Name").Select
Sheets("Name").Name = Wksht_Job_Title
ActiveWindow.DisplayVerticalScrollBar = True
Range("A1").Select
ActiveSheet.Protect Password:="XYZ2018", DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFormattingRows:=False, AllowSorting:=False, AllowFiltering:=False
'ActiveWorkbook.SaveAs Filename:=ECS_File_Name_Path _
, FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
Sheets(Wksht_Job_Title).Copy After:=Workbooks("XYZ Group Job Desc Workbook.xlsx").Sheets(1)
Windows("XYZ Job Description.xlsx").Activate
ActiveWorkbook.Close SaveChanges:=False
End If
If grpcounternext = 1 Or grpcounternext = "" Then
Windows("XYZ Group Job Desc Workbook.xlsx").Activate
ActiveWorkbook.SaveAs Filename:=Grp_ECS_Save_Dir & "" & Filename _
, FileFormat:=xlOpenXMLWorkbook, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
ActiveWorkbook.Close
End If
CurrRow = CurrRow + 1
Workbooks("Create XYZ Job Description Workbooks_2.xlsm").Activate
Range("A1").Select
Next I
Sheets("JD Workbook Requirements").Activate
Range("A1").Select
End Sub
Last edited by a moderator: