Sub SaveDecisionToNewBook()
Dim fName, newBook
Dim myRng As Range
Dim c As Range
Dim x
Application.ScreenUpdating = False
'advise the user
MsgBox "The Decision will now be saved as a new workbook." & vbCr & vbCr & _
"You must complete the document in the new file" & vbCr & vbCr & _
"and save the new file to BLP." & vbCr & vbCr & _
"You will be prompted for a File Name for the new workbook.", vbInformation + vbOKOnly, "Save File"
Set myRng = Sheets("Start").Range("Y2:Y90") 'the range where the final answer value is stored
For Each c In myRng 'loop through the cells in the range
If c.Value = "Y" Then 'determine which Decision is required
Select Case c.Offset(0, -1).Value 'check the column to the left
Case Is = "Yes17": Set x = Sheets("Export").Range("ILAInc") 'Increase
Case Is = "Yes23": Set x = Sheets("Export").Range("ILAMajVar") 'Major Variation
Case Is = "Opt19", "Opt22", "Opt25", "Opt28", "Opt31", "Opt43", "Opt40", "Opt52", "Opt55", "Opt58", "Opt61", "Opt64", "Opt67": Set x = Sheets("Export").Range("_ILA1") 'ILA 1
Case Is = "Opt20", "Opt23", "Opt26", "Opt29", "Opt32", "Opt44", "Opt41", "Opt50", "Opt53", "Opt56", "Opt59", "Opt62", "Opt65": Set x = Sheets("Export").Range("_ILA2") 'ILA 2
Case Is = "Opt21", "Opt24", "Opt27", "Opt30", "Opt33", "Opt42", "Opt45", "Opt51", "Opt54", "Opt57", "Opt60", "Opt63", "Opt66": Set x = Sheets("Export").Range("ILADec") 'Declined
Case Is = "Opt70", "Opt73", "Opt76", "Opt79", "Opt82", "Opt103", "Opt106": Set x = Sheets("Export").Range("_ILA1") 'ILA 1
Case Is = "Opt68", "Opt71", "Opt74", "Opt77", "Opt80", "Opt83", "Opt86", "Opt89", "Opt92", "Opt95", "Opt98", "Opt104", "Opt107", "Opt110": Set x = Sheets("Export").Range("_ILA2") 'ILA 2
Case Is = "Opt69", "Opt72", "Opt75", "Opt78", "Opt81", "Opt84", "Opt105", "Opt108": Set x = Sheets("Export").Range("ILA4") 'Declined
Case Is = "Yes19": Set x = Sheets("Export").Range("ILAMinor") ' Minor Variation
Case Is = "Yes24": Set x = Sheets("Export").Range("ILA9") ' Major Variation
Case Is = "Yes212": Set x = Sheets("Export").Range("ILA3Party") 'Charge
Case Else
MsgBox "No values present - please check input", vbOKOnly + vbInformation, "Cannot export - data missing"
Exit Sub
End Select
End If
Next c
x.Copy 'copy the required Decision
Set newBook = Workbooks.Add 'create a new workbook
With newBook.ActiveSheet
.Range("B1").Activate
.Paste
.Cells.PageBreak = xlPageBreakNone
.Columns(1).ColumnWidth = 2.57
.Columns(2).ColumnWidth = 1
.Columns("C:N").ColumnWidth = 8.43
.Columns("O").ColumnWidth = 2.43
.PageSetup.PrintArea = .Range("B1", Cells(.Columns.Count, 14)).End(xlUp)
End With
ActiveWindow.DisplayGridlines = False
Application.CutCopyMode = False 'clear copy/paste
fName = Application.GetSaveAsFilename(fileFilter:="Excel Files (*.xls), *.xls")
If fName <> False Then 'get a file name from the user
With newBook
.SaveAs Filename:=fName 'save the new workbook using the file name provided
.Close 'close the new workbook
End With
MsgBox "The Decision has now been saved." & vbCr & vbCr & _
"Remember to save the new file to BLP.", vbInformation + vbOKOnly, "Save File" 'advise the user
MsgBox "You may now close and save this workbook." & vbCr & vbCr & _
"This Decision Tree can be saved as a separate" & vbCr & vbCr & _
"file for the next steps to be followed.", vbInformation + vbOKOnly, "Close Workbook" 'advise the user
Else
MsgBox "You must save the Decision - it must be attached to BLP.", vbInformation + vbOKOnly, "Save the file"
newBook.Close False 'close the workbook
Exit Sub
End If
Application.ScreenUpdating = True
End Sub
Thanks again for your help.