In this chapter, we discuss two procedures for using data from other workbooks or worksheets: linking and consolidating. Linking is the process of using references to cells in external workbooks to get data into your worksheet. Consolidating involves combining or summarizing information from two or more worksheets (which can be in multiple workbooks).
Excel allows you to create formulas that contain references to other workbook files. With such formulas, the workbooks are linked in such a way that one depends on the other. The workbook that contains the external reference formulas is the dependent workbook (because it contains formulas that depend on another workbook). The workbook that contains the information used in the external reference formula is the source workbook (because it's the source of the information).
When you consider linking workbooks, you may ask yourself the following question: if Workbook A needs to access data that's in Workbook B, why not just enter the data into Workbook A in the first place? In some cases, you can. But the real value of linking becomes apparent when the source workbook is being continually updated by another person or group. Creating a link in Workbook A to Workbook B means that in Workbook A, you always have access to the most recent information in Workbook B because Workbook A is updated whenever Workbook B changes.
Linking workbooks also can be helpful if you need to consolidate different files. For example, each regional sales manager may store data in a separate workbook. You can create a summary workbook that first uses link formulas to retrieve specific data from each manager's workbook and then calculates totals across all regions.
Linking also is useful as a way to break up a large workbook into smaller files. You can create smaller workbooks that are linked with a few key external references.
Linking has its downside, however. External reference formulas are somewhat fragile, and accidentally severing the links that you create is relatively easy. You can prevent this mistake if you understand how linking works. Later in the chapter, we discuss some problems that may arise and how to avoid them. (See “Avoiding Potential Problems with External Reference Formulas.”)
The website for this book at |
You can create an external reference formula by using several different techniques:
Ideally, you won't have to enter too many external links manually. But it's good to know the structure of links in case you have to troubleshoot a problem. The general syntax for an external reference formula is as follows:
=[WorkbookName]SheetName!CellAddress
Precede the cell address with the workbook name (in brackets), followed by the worksheet name and an exclamation point. Here's an example of a formula that uses cell A1 in the Sheet1
worksheet of a workbook named Budget.xlsx
:
=[Budget.xlsx]Sheet1!A1
If the workbook name or the sheet name in the reference includes one or more spaces, you must enclose the text in single quotation marks. For example, here's a formula that refers to cell A1 on Sheet1
in a workbook named Annual Budget.xlsx
:
='[Annual Budget.xlsx]Sheet1'!A1
When a formula links to a different workbook, you don't need to open the other workbook. However, if the workbook is closed and not in the current folder, you must add the complete path to the reference. Here's an example:
='C:DataExcelBudget[Annual Budget.xlsx]Sheet1'!A1
If the workbook is stored on the Internet, the formula will also include the URL. Here's an example:
='https://d.docs.live.net/86a6d7c1f41bd208/Documents/[Annual Budget .xlsx]Sheet1'!A1
Entering external reference formulas manually usually isn't the best approach because you can easily make an error. Instead, have Excel build the formula for you, as follows:
When you point to the cell or range, Excel automatically takes care of the details and creates a syntactically correct external reference. When you're using this method, the cell reference is always an absolute reference (such as $A$1
). If you plan to copy the formula to create additional link formulas, you need to change the absolute reference to a relative reference by removing the dollar signs for the cell address.
As long as the source workbook remains open, the external reference doesn't include the path (or URL) to the workbook. If you close the source workbook, however, the external reference formulas change to include the full path (or URL).
Externally linked cells can also be an argument to a function, like SUM
or VLOOKUP
. Anywhere you would point to a cell on the same workbook as the function, you can point to a cell in another workbook. A SUM
function with an external link looks like this:
=SUM([source.xlsx]Sheet1!$B$3:$B$5)
Pasting links provides another way to create external reference formulas. This method is applicable when you want to create formulas that simply reference other cells rather than use links as part of a larger formula. Follow these steps:
This section discusses some key points that you need to know when working with links. Understanding these details can help prevent some common errors.
Excel enables you to create link formulas to unsaved workbooks (and even to nonexistent workbooks). Assume that you have two workbooks open (Book1 and Book2) and you haven't saved either of them. If you create a link formula to Book1 in Book2 and then save Book2, Excel displays a confirmation dialog box like the one shown in Figure 28.1.
Typically, you don't want to save a workbook that has links to an unsaved document. To avoid this prompt, save the source workbook first.
You can also create links to documents that don't exist. You may want to do so if you'll be using a source workbook from a colleague but the file hasn't yet arrived. When you enter an external reference formula that refers to a nonexistent workbook, Excel displays its Update Values dialog box, which resembles the Open dialog box. If you click Cancel, the formula retains the workbook name that you entered, but it returns a #REF!
error.
When the source workbook becomes available, you can choose Data ⇨ Queries & Connections ⇨ Edit Links to update the link. (See “Updating links” later in this chapter.) After doing so, the error goes away, and the formula displays its proper value.
When you open a workbook that contains links, Excel displays a dialog box (shown in Figure 28.2) that asks you what to do. Your options are as follows:
The Excel Help screen displays so that you can read about links.
What if you choose to update the links but the source workbook is no longer available? If Excel can't locate a source workbook that's referred to in a link formula, it displays a dialog box with two choices:
You can also access the Edit Links dialog box by choosing Data ⇨ Queries & Connections ⇨ Edit Links. The Edit Links dialog box lists all source workbooks plus other types of links to other documents.
When you open a workbook that contains one or more external reference formulas, by default Excel displays the dialog box that asks how you want to handle the links (refer to Figure 28.2). You can eliminate this prompt by changing a setting in the Startup Prompt dialog box (see Figure 28.4).
To display the Startup Prompt dialog box, choose Data ⇨ Queries & Connections ⇨ Edit Links. The Edit Links dialog box (refer to Figure 28.3) appears. In the Edit Links dialog box, click the Startup Prompt button and then select the option that describes how you want to handle the links.
If you want to ensure that your link formulas have the latest values from their source workbooks, you can force an update. For example, say that you just discovered that someone made changes to the source workbook and saved the latest version to your network server. In such a case, you may want to update the links to display the current data.
To update linked formulas with their current value, open the Edit Links dialog box (Data ⇨ Queries & Connections ⇨ Edit Links), choose the appropriate source workbook in the list, and then click the Update Values button (refer to Figure 28.3). Excel updates the link formulas with the latest version of the source workbook.
In some cases, you may need to change the source workbook for your external references. For example, say that you have a worksheet that has links to a file named Preliminary Budget
, but you later receive a finalized version named Final Budget
.
You can change the link source using the Edit Links dialog box (choose Data ⇨ Queries & Connections ⇨ Edit Links). Select the source workbook that you want to change, and click the Change Source button (refer to Figure 28.3). Excel displays the Change Source dialog box from which you can select a new source file. After you select the file, all external reference formulas that referred to the old file are updated.
If you have external references in a workbook and then decide that you no longer need the links, you can convert the external reference formulas to values, thereby severing the links. To do so, access the Edit Links dialog box (choose Data ⇨ Queries & Connections ⇨ Edit Links), select the linked file in the list, and then click Break Link (refer to Figure 28.3).
Using external reference formulas can be quite useful, but the links may be unintentionally severed. As long as the source file hasn't been deleted, you can almost always reestablish lost links. If you open the workbook and Excel can't locate the file, you see a dialog box that enables you to specify the workbook and re-create the links. You also can change the source file by clicking the Change Source button in the Edit Links dialog box (choose Data ⇨ Queries & Connections ⇨ Edit Links). The following sections discuss some pointers that you must remember when you use external reference formulas.
If you or someone else renames the source document or moves it to a different folder, Excel won't be able to update the links. You need to use the Edit Links dialog box and specify the new source document. (See “Changing the link source” earlier in this chapter.)
If both the source workbook and the dependent workbook are open, Excel doesn't display the full path to the source file in the external reference formulas. If you use the File ⇨ Save As command to give the source workbook a new name, Excel modifies the external references to use the new workbook name. In some cases, this change may be what you want. But in other cases, it may not.
Here's an example of how using File ⇨ Save As can cause a problem. You finished working on a source workbook and save the file. Then you decide to be safe and make a backup copy on a different drive, using File ⇨ Save As. The formulas in the dependent workbook now refer to the backup copy, not the original source file. This is not what you want.
Bottom line? Be careful when you choose File ⇨ Save As with a workbook that is the source of a link in another open workbook.
If you open a workbook that is the source for a link, be extremely careful if the workbook that contains the link isn't open. For example, if you add a new row to the source workbook, all of the cells move down one row. When you open the dependent workbook, it continues to use the old cell references, which is probably not what you want.
You can avoid this problem by doing the following:
The following link formula refers to cell C21 on Sheet1
in the budget.xlsx
workbook:
=[budget.xlsx]Sheet1!$C$21
If cell C21 is named Total
, you can write the formula using that name:
=budget.xlsx!Total
Using a name ensures that the link retrieves the correct value, even if you add or delete rows or columns from the source workbook.
By the way, notice that the filename isn't enclosed in brackets. That's because Total
is assumed to be a workbook-level name and doesn't need to be qualified with a sheet name. If Total
were a sheet-level name (defined on Sheet1
), the formula would be as follows:
=[budget.xlsx]Sheet1!Total
See Chapter 4, “Working with Excel Ranges and Tables,” for more information about creating names for cells and ranges. |
If your source workbook contains a list of months and values and you want to return the July value, you can use a formula such as the following:
=VLOOKUP("July",source.xlsx!MonthValues,2,FALSE)
The source workbook has a workbook-level name MonthValues
. If you used a normal cell reference, you would still have a problem if rows were inserted into the source workbook. However, by naming the entire range, you don't have to make a named range for each month separately.
Excel doesn't place many limitations on the complexity of your network of external references. For example, Workbook A can contain external references that refer to Workbook B, which can contain an external reference that refers to Workbook C. In this case, a value in Workbook A can ultimately depend on a value in Workbook C. Workbook B is an intermediary link.
We don't recommend using intermediary links, but if you must use them, be aware that Excel doesn't update external reference formulas if the dependent workbook isn't open. In the preceding example, assume that Workbooks A and C are open. If you change a value in Workbook C, Workbook A won't reflect the change because you didn't open Workbook B (the intermediary link).
The term consolidation, in the context of worksheets, refers to several operations that involve multiple worksheets or multiple workbook files. In some cases, consolidation involves creating link formulas. Here are two common examples of consolidation:
These types of tasks can be difficult or quite easy. The task is easy if the information is laid out in the same way in each worksheet. If the worksheets aren't laid out identically, they may be similar enough. In the second example, some budget files submitted to you may be missing categories that aren't used by a particular department. In this case, you can use a handy feature in Excel that matches data by using row and column titles. We discuss this feature in “Consolidating worksheets by using the Consolidate dialog box” later in this chapter.
If the worksheets bear little or no resemblance to each other, your best option may be to edit the sheets so that they correspond to one another. Or return the files to the department heads and ask that they submit them using a standardized format. Better yet, redesign your workflow to use normalized tables that can be used as the source for PivotTables.
You can use any of the following techniques to consolidate information from multiple workbooks:
Consolidating with formulas simply involves creating formulas that use references to other worksheets or other workbooks. Here are the primary advantages to using this method of consolidation:
If you're consolidating the worksheets in the same workbook and all the worksheets are laid out identically, the consolidation task is simple. You can just use standard formulas to create the consolidations. For example, to compute the total for cell A1
in worksheets named Sheet2
through Sheet10
, enter the following formula:
=SUM(Sheet2:Sheet10!A1)
You can enter this formula manually or use the multisheet selection technique. You can then copy this formula to create summary formulas for other cells.
See Chapter 4, “Working with Excel Ranges and Tables,” for more on multisheet selection. |
If the consolidation involves other workbooks, you can use external reference formulas to perform your consolidation. For example, if you want to add the values in cell B2 from Sheet1
in two workbooks (named Region1
and Region2
), you can use the following formula:
=[Region1.xlsx]Sheet1!B2+[Region2.xlsx]Sheet1!B2
You can include any number of external references in this formula, up to the 8,000-character limit for a formula. However, if you use many external references, such a formula can be quite lengthy and confusing if you need to edit it.
If the worksheets that you're consolidating aren't laid out in the same way, you can still use formulas, but you need to ensure that each formula refers to the correct cell—a task that is both tedious and error prone.
Another method of consolidating information is to use the Paste Special dialog box. This technique takes advantage of the fact that the Paste Special dialog box can perform a mathematical operation when it pastes data from the Clipboard. For example, you can use the Add option to add the copied data to the selected range. Figure 28.5 shows the Paste Special dialog box.
This method is applicable only when all the worksheets that you're consolidating are open. The disadvantage is that the consolidation isn't dynamic. In other words, it doesn't generate formulas that refer to the original source data. So, if any data that was consolidated changes, the consolidation is no longer accurate.
Here's how to use this method:
Repeat these steps for each source range that you want to consolidate. Make sure that the consolidation location in step 2 is the same for each paste operation.
For the ultimate in data consolidation, use the Consolidate dialog box. This method is flexible, and in some cases it even works if the source worksheets aren't laid out identically. This technique can create consolidations that are static (no link formulas) or dynamic (with link formulas). The data consolidation feature supports the following methods of consolidation:
Figure 28.6 shows the Consolidate dialog box, which appears when you choose Data ⇨ Data Tools ⇨ Consolidate.
The following is a description of the controls in this dialog box:
The simple example in this section demonstrates the power of the data consolidation feature. Figure 28.7 shows three single-sheet workbooks that will be consolidated. These worksheets report three months of product sales. Notice, however, that all don't report on the same products. In addition, the products aren't listed in the same order. In other words, these worksheets aren't laid out identically. Creating consolidation formulas manually would be a tedious task.
These workbooks are available on this book's website at |
To consolidate this information, start with a new workbook. You don't need to open the source workbooks, but consolidation is easier if they're open. Follow these steps to consolidate the workbooks:
Region2
workbook, or you can simply edit the existing reference by changing Region1
to Region2
and then clicking Add. This reference is added to the All References list.Region2
to Region3
and then clicking Add. This final reference is added to the All References list.Excel creates the consolidation, beginning at the active cell. Notice that Excel created an outline, which is collapsed to show only the subtotals for each product. If you expand the outline (by clicking the number 2 or the plus-sign symbols in the outline), you can see the details. Examine it further, and you discover that each detail cell is an external reference formula that uses the appropriate cell in the source file. Therefore, the consolidated results are updated automatically when values are changed in any of the source workbooks.
Figure 28.8 shows the result of the consolidation, and Figure 28.9 shows the detail information (with the outline expanded).
For more information on Excel outlines, see Chapter 27, “Creating and Using Worksheet Outlines.” |
When you choose the option to create formulas, the external references in the consolidation workbook are created only for data that exists at the time of the consolidation. Therefore, if new rows are added to any of the original workbooks, the consolidation must be redone. Fortunately, the consolidation parameters are stored with the workbook, so it's a simple matter to rerun the consolidation if necessary. That's why specifying complete columns and including extra columns (step 3 in the preceding section) is a good idea.
Excel remembers the references that you entered in the Consolidate dialog box and saves them with the workbook. That way, if you want to refresh a consolidation, you won't have to reenter the references. Just display the Consolidate dialog box, verify that the ranges are correct, and then click OK.
Excel is flexible regarding the sources that you can consolidate. You can consolidate data from the following:
And, of course, you can mix and match any of the preceding choices in a single consolidation.
If you perform the consolidation by matching labels, be aware that the matches must be exact. For example, Jan doesn't match January. The matching is not case sensitive, however, so April does match APRIL. In addition, the labels can be in any order, and they don't need to be in the same order in all of the source ranges.
If you don't select the Create Links to Source Data check box, Excel generates a static consolidation. (It doesn't create formulas.) Therefore, if the data on any of the source worksheets changes, the consolidation won't update automatically. To update the summary information, you need to choose Data ⇨ Data Tools ⇨ Consolidate again.
If you do select the Create Links to Source Data check box, Excel creates a standard worksheet outline that you can manipulate by using the techniques described in Chapter 27. |