by Svetlana Cheusheva, updated on
The tutorial provides a collection of macros to duplicate sheets in Excel: copy and rename based on cell value, copy multiple sheets, copy an active worksheet to another file without opening it, and more.
Manually copying sheets in Excel is pretty quick and straightforward... if performed just once or twice. Duplicating multiple sheets multiple times is boring and time consuming. On this page, you will find a handful of useful macros to automate this task.
This simplest one-line macro does exactly what its name suggests - copies the active sheet to a new workbook.
If you'd like to copy several sheets from the active workbook to a new one, select all the worksheets of interest and run this macro:
Depending on where you want to insert the copied sheet, use one of the following macros.
This macro copies the active sheet before all other worksheets in the destination file, Book1 in this example. To copy to another file, replace "Book1.xlsx" with the full name of your target workbook.
This piece of code duplicates the active worksheet and places the copy to the end of Book1. Again, please remember to replace "Book1.xlsx" with the name of your destination workbook.
Note. For the macros to work, the target workbook must be saved on your hard drive or network.
To be able to copy the current sheet to any open workbook, you can create a UserForm (named UserForm1) with a ListBox control (named ListBox1) and two buttons:
Next, double-click the form and paste the below code in the Code window:
With the UserForm in place, you can use one of the following macros to copy the active sheet to the workbook of your choosing.
Copy sheet to the beginning of the selected workbook:
Copy sheet to the end of the selected workbook:
When run in Excel, the macro will show you a list of all currently opened workbooks. You select the needed one and click OK:
When you copy a sheet in Excel, the replica is given a name in the default format like Sheet1 (2). The following macros can spare you the trouble of changing the default name manually.
This code duplicates the active worksheet, names the copy as "Test Sheet" (you are free to replace it with any other name you like), and places the copied sheet at the end of the current workbook.
To allow the user to specify the name for the copied sheet, use this code:
Upon running, the macro displays the following input box, in which you type the desired name and press OK:
In some situations, it may be more convenient to name a copy with a specific cell value, for example, a column header. For this, you simply take the above code and supply the value of the currently selected cell to the input box automatically. As with the previous example, the copy will be placed at the end of the active workbook.
The trickiest part would be to have your users always select the correct cell before running the macro :)
Alternatively, you can hardcode the address of the cell by which the copy should be named, cell A1 in the below code. To name the copied worksheet based on another cell, replace A1 with an appropriate cell reference.
This macro copies the active sheet to the end of a closed workbook. The name of another workbook is not specified in the code - the macro will open the standard Windows Explorer window and allow you to choose any destination file:
After you select the file and click Open, the macro will copy the active sheet and close the target workbook automatically.
This macro enables you to copy a worksheet from another Excel file without opening it. The copied sheet will be inserted at the end of the current workbook.
Just remember to make a couple of replacements in the code:
Sometimes, you may need to duplicate the same sheet more than once, for instance to test different formulas on the same data set. This can be easily done with the following macro.
Open the original sheet, run the macro, specify how many copies of the active sheet you want to make, and click OK:
To copy a sheet in Excel with one of the above macros, you can either insert the VBA code into your own book or run a macro from our sample workbook.
To insert the code in your workbook, perform these steps:
For the detailed step-by-step instructions, please see How to insert VBA code in Excel.
Alternatively, you can download our sample workbook to Duplicate Excel Sheets and run the code from there.
The sample workbook contains the following macros:
CopySheetToNewWorkbook - copies the current worksheet to a new workbook.
CopySelectedSheets - copies multiple sheets that you select to a new workbook.
CopySheetToBeginningAnotherWorkbook - copies the active sheet to the beginning of another workbook.
CopySheetToEndAnotherWorkbook - copies the active sheet to the end of another Excel file.
CopySheetAndRename - duplicates the current sheet, renames it as specified by the user, and puts the copy after all other sheets in the current workbook.
CopySheetAndRenamePredefined - duplicates the active sheet, gives a hardcoded name to the copy and places it at the end of the current workbook.
CopySheetAndRenameByCell - makes a copy of the active sheet and renames it based on the selected cell value.
CopySheetAndRenameByCell2 - copies the active sheet and renames it based on the hardcoded cell address.
CopySheetToClosedWorkbook - allows you to copy sheet to a closed workbook.
CopySheetFromClosedWorkbook - enables you to copy a sheet from another Excel file without opening it.
DuplicateSheetMultipleTimes - lets you duplicate a sheet in Excel multiple times.
To run the macro in your Excel, just do the following:
That's how you can duplicate a sheet in Excel with VBA. I thank you for reading and hope to see you on our blog next week!
Table of contents