Help me modify the VBA code to create only workbook with data.

I have a workbook with the following worksheets “PreviousFN”, “CurrentFN”, “OmittedMbrs”, “NewMbrs”, “CommonEID” , “PayPeriod”, “Section” and “ImportHere”

I want to split this workbook create workbooks but I don’t want to create all the workbooks. I want to create “PreviousFN”, “CurrentFN”, “OmittedMbrs”, “NewMbrs” and “CommonEID” only and only if they have data in each worksheet. They all have headings.

The present code is creating workbooks of all the sheets. I don’t want to create “PayPeriod”, “Section” and “ImportHere”. “CommonEID” does not have the data.

Please, I need help to modify the code to do so.

Sub SplitWorkBook()
Dim xPath As String
Dim xWs As Worksheet
xPath = Application.ActiveWorkbook.Path
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each xWs In ThisWorkbook.Sheets
Application.ActiveWorkbook.SaveAs Filename:=xPath & "\" & xWs.Name & ".xls" '<< hardcoded the folder
Application.ActiveWorkbook.Close False
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub

Top Contributor Asked on May 3, 2017 in Excel.
Add Comment
0 Answer(s)
  • Found this useful?

    Please share using the share button above.

    If you found the answer is best answer for your question, Please mark as 'best answer' by clicking on the right tick mark icon at the left side of the answer.

    Found the answer useful and wants to credit the user, then vote the answer (vote up).

  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.