This code works but I would like to make it more readable and remove excessive or redundant lines. Anyone want to try?
Thanks
Code:
‘Create and prepare the new workbook
‘Exit if workbook already exists<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
fileExistsStatus = Dir(NewWB)<o:p></o:p>
If fileExistsStatus <> "" Then<o:p></o:p>
MsgBox “The Workbook already exists – delete it and restart macro”<o:p></o:p>
Exit Sub<o:p></o:p>
End If<o:p></o:p>
‘Create workbook with 2 worksheets: Shortage and Reference<o:p></o:p>
On Error GoTo Err_RestoreDefaultWorksheet<o:p></o:p>
‘Save the orininal number of worksheets created with a new workbook<o:p></o:p>
OrgNumOfWS = Application.SheetsInNewWorkbook<o:p></o:p>
Application.SheetsInNewWorkbook = 2<o:p></o:p>
Workbooks.Add<o:p></o:p>
Worksheets("Sheet1").Name = “Shortage”<o:p></o:p>
Worksheets("Sheet2").Name = “Reference”<o:p></o:p>
Err_RestoreDefaultWorksheets:
‘Restore the original number of worksheets created with a new workbook<o:p></o:p>
Application.SheetsInNewWorkbook = OrgNumOfWS <o:p></o:p>
<o:p></o:p>
Thanks