Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. 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: Referencing External Cell Colors.
by Allen Wyatt
(last updated July 25, 2015)
Beth asked how to copy the color formatting of an external cell to a cell in the current workbook. Unfortunately, there is no intrinsic way to do this by using the linking features of Excel. You can, however, copy formatting from one workbook to another by using a macro.
As an example, consider the following macro code:
Dim lMyColor As Long Workbooks.Open Filename:="C:\mypath\myworkbook.xlsm" lMyColor = Range("A1").Interior.Color Windows("TargetBook.xlsm").Activate Range("E8").Interior.Color = lMyColor
This code opens a workbook (myworkbook.xlsm) and grabs the fill color from cell A1. It then switches back to the target workbook (from which this code is assumed to be running) and stuffs the fill color into cell E8.
This approach works great if you are copying the fill color from a single cell to a single cell. If you, instead, want to copy a range of cells or copy more formatting than just the fill color, then you might be better served with this approach:
Workbooks.Open Filename:= "C:\mypath\myworkbook.xlsm" Range("A1:B6").Copy Windows("TargetBook.xlsm").Activate Range("E8").PasteSpecial Paste:=xlPasteFormats, _ Operation:=xlNone, SkipBlanks:=False, _ Transpose:=False
Again, this code opens the external workbook. It then uses the .Copy method for a range of cells (A1:B6). After switching to the target workbook, the formats from those cells are pasted into the cells beginning at E8.
If you decide to use code like this, you can place it in the Auto_Open macro for the target workbook. Of course, you need to modify the code so that it refers to the proper path and workbook names, along with the desired source and target ranges.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (11169) applies to Microsoft Excel 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Excel here: Referencing External Cell Colors.
Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!
Is the information in your cells too jammed up? Here are some ways you can add some white space around that information so it ...Discover More
If you use an Excel worksheet for entering data (a quite common task, actually), then you need to be concerned with how ...Discover More
Professional typesetting has, in many ways, spoiled us. One way this is evident is in the preference we show for making ...Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
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.