Sub create_CS_Doc()
Dim TotRows As Integer
…….
Workbooks("Create Statements.xlsm").Activate
TotRows = Sheets("Merge Wkshts").Cells(1, 1)
CurrRow = 2
Workbooks("Create Statements.xlsm").Activate
TotRows2 = Sheets("Pivot Table").Cells(1, 1)
CurrRow2 = 2
For I = 1 To TotRows
StartLine = Sheets("Pivot Table").Cells(CurrRow2, 5)
EndLine = Sheets("Pivot Table").Cells(CurrRow2, 6)
EECount = Sheets("Pivot Table").Cells(CurrRow2, 4)
RowNo = Sheets("Merge Wkshts").Cells(CurrRow, 90)
Filename = Sheets("Merge Wkshts").Cells(CurrRow, 91)
GrpCtr = Sheets("Merge Wkshts").Cells(CurrRow, 92)
GrpCounterNext = Sheets("Merge Wkshts").Cells(CurrRow + 1, 92)
CS_Type = Sheets("Merge Wkshts").Cells(CurrRow, 98)
CreateCS = Sheets("Merge Wkshts").Cells(CurrRow, 99)
ICSFilename = Sheets("Merge Wkshts").Cells(CurrRow, 100)
If GrpCtr = 1 Then
Workbooks.Open Filename:=Grp_ECS_Path & "\" & " Group Statement.xlsm"
………
'Copy Name into Worksheet
Windows("Create Statements.xlsm").Activate
Sheets("Merge Wkshts").Select
RangeArea = "B" & StartLine & ":B" & EndLine
Range(RangeArea).Select
Selection.Copy
Windows("Group Statement.xlsm").Activate
Sheets("Data").Select
Range("A2").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
……………
Range("A1").Select
CurrRow2 = CurrRow
End If
If CS_Type = 1 Then
Workbooks.Open Filename:=ECS_Template_Path & "\ Individual CS.xlsx"
'Enter Demographic information
Range("C7").Select
ActiveCell.FormulaR1C1 = Name
………….
Workbooks("Individual CS.xlsx").Activate
Sheets("Name").Select
Sheets("Name").Name = Name
ActiveSheet.Protect Password:="KSS2013", DrawingObjects:=True, Contents:=True, Scenarios:=True,
AllowFormattingRows:=False, AllowSorting:=False, AllowFiltering:=False
Sheets(Name).Copy After:=Workbooks("Group Statement.xlsm").Sheets(4)
…….
Windows("Individual CS.xlsx").Activate
ActiveWorkbook.Close SaveChanges:=False
End If
If CS_Type = 2 Then
Workbooks.Open Filename:=ECS_Template_Path & "\Second Individual CS.xlsx"
'Enter Demographic information
Range("C7").Select
……….
End If
'Save Grp Workbook
If GrpCounterNext = 1 Or GrpCounterNext = "" Then
Windows("Group Statement.xlsm").Activate
ActiveWorkbook.SaveAs Filename:=Grp_ECS_Save_Dir & "\" & Filename _
, FileFormat:=xlOpenXMLWorkbookMacroEnabled, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
ActiveWorkbook.Close
End If
CurrRow = CurrRow + 1
Workbooks("Create Statements.xlsm").Activate
Range("A1").Select
Next I
End Sub
I think the issue is with the GrpCounterNext code:
If GrpCounterNext = 1 Or GrpCounterNext = "" Then
Windows("Group Statement.xlsm").Activate
ActiveWorkbook.SaveAs Filename:=Grp_ECS_Save_Dir & "\" & Filename _
, FileFormat:=xlOpenXMLWorkbookMacroEnabled, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
ActiveWorkbook.Close
End If
Below is what the data looks like in the "Merge Wkshts" worksheet:
Filename GrpCtr
Group_1.xlsx 1
Group_2.xlsx 1
Group_2.xlsx 2
Group_3.xlsx 1
Group_3.xlsx 2
Group_3.xlsx 3
Each row represents a worksheet that is being built into the workbook. Group_1 only has one worksheet. When GrpCounterNext = 1, then the program saves the file and the program should start another workbook (e.g., Group_2). It works for all other rows except when there are two consecutive rows where the GrpCtr =1.
Any ideas? Again, thanks for your help.