How to Split Each Worksheet in an Excel Workbook into Separate Files Using VBA

How to Split Each Worksheet in an Excel Workbook into Separate Files Using VBA

Managing large Excel files with multiple sheets? ๐Ÿ˜ฉ Want to separate each worksheet into its own Excel file โ€” with all formulas and formatting intact?

This step-by-step guide will help you do exactly that using a simple VBA macro! ๐Ÿ’ป


โœ… Why You Might Need This

  • You have a workbook with 25+ sheets and want to save them individually.
  • You want to preserve formulas, formatting, and structure.
  • You want an easy way to select the destination folder for the split files.

๐Ÿ› ๏ธ Example Used in This Blog

In this example, we created a sample workbook called Sales_Report_2025.xlsm with 3 sheets:

  • North
  • South
  • West

Each sheet contains:

  • Product sales data ๐Ÿ›๏ธ
  • Formulas (like =Quantity * Price) to auto-calculate totals
  • Proper formatting (bold headers, colored cells, โ‚น currency format)

๐Ÿ“Œ Screenshot: Sample data in โ€œNorthโ€ sheet ๐Ÿ‘‰

๐Ÿ“Œ Screenshot: Sample data in โ€œSouthโ€ sheet ๐Ÿ‘‰

๐Ÿ“Œ Screenshot: Sample data in โ€œWestโ€ sheet ๐Ÿ‘‰


๐Ÿ“œ VBA Macro to Split Worksheets

Hereโ€™s the VBA code to copy-paste into your Excel:

๐Ÿงฉ What It Does:

  • Prompts you to select a destination folder
  • Saves each sheet as its own .xlsx file
  • Preserves formulas, formatting, and layout

๐Ÿ“‹ Steps to Run the Macro:

  1. Press Alt + F11 to open the VBA Editor.
  2. Insert โ†’ Module
  3. Paste the following code:
    • Sub ExportSheetsToFiles()
      Dim ws As Worksheet
      Dim FolderPath As String
      Dim NewWorkbook As Workbook
      FolderPath = "C:\Users\PREMIUM\Desktop\Excel Data\Extracted\" ' Change the path to your desired folder
      On Error GoTo ErrorHandler ' Enable error handling
      For Each ws In ThisWorkbook.Sheets
      ws.Copy ' Create a new workbook with the copied sheet
      Set NewWorkbook = ActiveWorkbook ' Reference the new workbook ' Save the new workbook NewWorkbook.SaveAs FolderPath & ws.Name & ".xlsx" NewWorkbook.Close SaveChanges:=False ' Close the new workbook without saving changes again Application.Wait (Now + TimeValue("0:00:02")) ' Wait for 2 seconds to prevent Excel from freezing
      Next ws
      MsgBox "All sheets have been saved successfully!", vbInformation ' Confirmation message
      Exit Sub
      ErrorHandler:
      MsgBox "An error occurred: " & Err.Description, vbCritical ' Show an error message if something goes wrong
      End Sub

๐Ÿ“Œ Final Output Example

After running the macro:

  • You’ll have 3 separate files:
    • North.xlsx
    • South.xlsx
    • West.xlsx
  • Each file will contain the original formatting, formulas, and values ๐ŸŽฏ

๐Ÿ“ฅ Try it out and share your feedback in the comments!

Download the Sample file : Sales_Report_2025.xlsm

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *