Copying worksheets

Overview

The [highlight txt=’copy worksheet’] instruction allows a user to copy a whole worksheet from a particular Excel workbook to another Excel workbook. The instruction can be configured to either 1) append a copy of the worksheet to the Target file under any name the user chooses to specify, or 2) replace a worksheet in the Target file if the user has specified the name of the worksheet to be replaced.

[message type=”warning”]For the purposes of this article we are going to use two simple and fictitious Excel files. They have already been uploaded into a data step. You will want to replace these files with those of your own.[/message]

Before we get started

Please further create a ‘Manipulate a file’ or ‘Multiple file manipulations’ action step so that you can add and use instructions.

The source file that we are going to use looks like this:

The target file that we are going to use is a standard fresh Excel workbook which contains 3 empty worksheets.

Steps

1. Create a ‘Copy worksheet’ instruction.

2. Link the file named “Source” as the source file and the file named “Target” as the target file.

3. For the Source file, select Sheet1.

4. Type “New Sheet” into the New Worksheet Name field. This will allow Sheet1 to be appended to the end of Target workbook under the name of “New Sheet”. If a worksheet with the name of “New Sheet” already exists in the Target workbook, the step will fail. However, if a worksheet with the name of “New Sheet” already exists in the Target workbook, an user can simply tick the ‘Replace worksheet if already exist?’ checkbox so that Sheet1 will replace it (under the name of “New Sheet”).

5. Save and run the step.

6. After the step finishes running, download and open the target file. It will resemble the image below:

Recent Posts

Leave a Comment