Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, and 2016. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Creating Individual Workbooks.

Creating Individual Workbooks

by Allen Wyatt
(last updated March 25, 2017)

5

If you use Excel quite a bit, you know you may get some rather large workbooks from colleagues. Often it is desirable to break the workbook down, so that each worksheet is in its own workbook. While this can be done manually, the process quickly becomes tedious if you have a lot of breaking down to do.

This sort of repetitive work is a natural for a macro. The following macro, called BreakItUp, creates individual workbook files based on the worksheets in the current workbook. Thus, if the current workbook contains 25 worksheets, running this macro results in 25 individual Excel workbook files being created. Each workbook has a single worksheet, and the name of the workbook is the same as that of the worksheet.

Sub BreakItUp()
    Dim sht As Worksheet
    Dim NFName As String
    Const WBPath = "C:\"

    For Each sht In ActiveWorkbook.Worksheets
        sht.Copy
        NFName = WBPath & sht.Name & ".xls"
        ActiveWorkbook.SaveAs FileName:=NFName, _
            FileFormat:=xlNormal, CreateBackup:=False
        ActiveWindow.Close
    Next
End Sub

The BreakItUp macro stores the new workbooks in the root directory on the C: drive. If you want your workbooks saved in a different place, you can simply change the line in which the WBPath constant is created.

You should also know that it is relatively easy to crash this macro. For instance, if you use a character in a worksheet name that is not “legal” for a file name, the macro will rudely stop when it tries to create the file. Of course, you could easily make the modifications to the macro to check for and replace such illegal characters.

Another potential pitfall for the macro is that it will stop running if a file already exists that has the same name as a worksheet. For instance, let's suppose you have a worksheet named MySheet1. If there is already a file on disk called MySheet1.xls, then the macro will stop when it tries to overwrite the file. You can get around this by making sure there are no file name conflicts in the directory where the workbooks are being saved.

Finally, if your original workbook has formulas that reference other worksheets (besides the one on which the formula occurs), then those formulas won't work in the broken-out workbooks. For this reason, you'll want to carefully check what is created to make sure the workbooks fit your needs.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12273) applies to Microsoft Excel 2007, 2010, 2013, and 2016. You can find a version of this tip for the older menu interface of Excel here: Creating Individual Workbooks.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Specifying Monitor Resolution

When using Word to create content that will end up on the Web, it is helpful to know the probably screen resolution of those ...

Discover More

Adding Phrases to the Grammar Checker

Word's grammar checker dutifully tries to mark all the questionable grammar in your sentences. If you are tired of a certain ...

Discover More

Changing Existing Captions

Word allows you to automatically create captions for various elements of your document, such as figures and tables. These ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

Closing a Read-Only Workbook

When you create a workbook that is read-only, users can still make changes to the workbook. When they exit, they are prompted ...

Discover More

Merging Many Workbooks

If you need to combine the contents of a bunch of workbooks into a single workbook, the process can get tedious. Here's a ...

Discover More

Accessing a Problem Shared Workbook

What are you to do is you share a workbook with others, and then suddenly the workbook won't open properly? Dealing with a ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is four less than 4?

2017-03-27 10:51:58

Dave Bonin

As useful as this macro might be, I've often wondered whether a better approach would be to make X copies of the workbook where X is the number of worksheets. Each workbook copy would then remove all worksheets except the one which is supposed to remain.

Why do this? To preserve the macros and special formatting that might otherwise be lost.


2017-03-27 03:05:59

Alan Elston

Hi Alex
Thanks, I have it working now. ( I had to Dim a couple of variables ( nmUseAddrs As String , i As Long ) as I use Option Explicit ).
Alan


2017-03-26 19:34:33

Alex B

Hello Alan, I tend to reuse a lot of code and stick it in a Library module, so I forgot that I called the code below. (Your point 2). Sorry about the omission.
PS: I use selected sheets in my main macro rather than all sheets, it makes it easier when testing if nothing else.

Function FindAddress(FindString, Optional Whole_Part)
' Find a supplied text in the active worksheet and return the address information.
If Whole_Part = "" Then Whole_Part = xlWhole
On Error GoTo ErrorHandling

FindAddress = Cells.Find(What:=FindString, After:=Range("A1"), LookIn:=xlFormulas, LookAt _
:=Whole_Part, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Address

Exit Function:

ErrorHandling:

FindAddress = ""

End Function


2017-03-26 04:50:03

Alan Elston

Hi Alex B,
Thanks for sharing. I tried your codes..
( _1) End Function was missing on your first Function )

_2) I error at
FindAddress(

_...........
This is the code I tried. ( I am using XL 2007 and saving as .xlsm )

' https://excelribbon.tips.net/T012273_Creating_Individual_Workbooks.html
Sub BreakItUp()
Dim Ws As Worksheet
Dim NFName As String, WBPath As String
Let WBPath = ThisWorkbook.Path & "\" ' "C:\"
For Each Ws In ActiveWorkbook.Worksheets
Ws.Copy ' This effectively makes a copy File with one Worksheet in it, Ws
' NFName = WBPath & Ws.Name & ".xls"
' ActiveWorkbook.SaveAs Filename:=NFName, FileFormat:=xlNormal, CreateBackup:=False
Let NFName = WBPath & Ws.Name & ".xlsm"
ActiveWorkbook.SaveAs Filename:=NFName, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
Call DeleteBadRefs_and_Links(ActiveWorkbook)
Call BreakLinks(ActiveWorkbook)
ActiveWindow.Close
Next
End Sub
Function DeleteBadRefs_and_Links(wkb As Workbook)
Dim nm As Name
For Each nm In wkb.Names
If InStr(1, nm.RefersTo, "#REF!") > 0 Or InStr(1, nm.RefersTo, "[") > 0 Then
Let nmUseAddrs = FindAddress(FindString:=nm.Name, Whole_Part:=xlPart)
If nmUseAddrs <> "" Then
With wkb.Sheets(1).Range(nmUseAddrs)
.Cells.Copy
.Cells.PasteSpecial xlPasteValues
.Cells(1).Select
End With
End If
nm.Delete
End If
Next nm
End Function
Function BreakLinks(wkb As Workbook)
Dim Links As Variant
Links = wkb.LinkSources(Type:=xlLinkTypeExcelLinks)
If Not (IsEmpty(Links)) Then
For i = 1 To UBound(Links)
wkb.BreakLink _
Name:=Links(i), _
Type:=xlLinkTypeExcelLinks
Next i
End If
End Function


2017-03-25 06:58:17

Alex B

There is quite a bit more you could add to this. To start with it would be safer to save the spreadsheet as xlsx so that you at least don't hit the xls row limit issue when you save it.

From my base code I make 2 function calls to:-
- replace range names linked to the original s/sheet with values and then delete the range name
- Break the Links to the original s/sheet replacing it with values.
The functions I am using are below.

Function DeleteBadRefs_and_Links(wkb As Workbook)

Dim nm As Name

For Each nm In wkb.Names
If InStr(1, nm.RefersTo, "#REF!") > 0 _
Or InStr(1, nm.RefersTo, "[") > 0 Then

nmUseAddrs = FindAddress(FindString:=nm.Name, Whole_Part:=xlPart)

If nmUseAddrs <> "" Then
With wkb.Sheets(1).Range(nmUseAddrs)
.Cells.Copy
.Cells.PasteSpecial xlPasteValues
.Cells(1).Select
End With
End If

nm.Delete
End If
Next nm


Function BreakLinks(wkb As Workbook)

Dim Links As Variant
Links = wkb.LinkSources(Type:=xlLinkTypeExcelLinks)

If Not (IsEmpty(Links)) Then
For i = 1 To UBound(Links)
wkb.BreakLink _
Name:=Links(i), _
Type:=xlLinkTypeExcelLinks
Next i
End If

End Function


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.