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.
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (11169) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Office 365. You can find a version of this tip for the older menu interface of Excel here: Referencing External Cell Colors.
Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!
Need to replace the formats applied to some cells with a different format? You can use Excel's Find and Replace tool to ...
Discover MoreWant to figure out if the text in a cell is bold? The best approach is to use your own user-defined function, as ...
Discover MoreWhen you enter something into a cell, Excel tries to figure out if your entry should be formatted in a particular way. ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2015-07-26 04:38:11
Eyal
What can Ido if the format is based on conditional formating? I see that it doesn't work when you use conditional formating
2015-07-25 07:07:48
Petros
I believe Willy nailed it!
The Excel color commander FREE add-in can help you create stylish Excel dashboards or even a custom theme that can reflect your company logo colors.
The addin offers a COLOR-PICKER that can copy any color on the monitor, plus easy access to cloud color generators and ColorIndex buttons on the ribbon.
Favorite custom colors are stored on disc and shown in the ribbon! Read more:
http://www.spreadsheet1.com/excel-color-commander.html
2015-07-25 06:04:20
Willy Vanhaelen
You don't need a macro to do this. If both workbooks are open in the same instance of Excel you can perfectly copy formatting between them.
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2021 Sharon Parq Associates, Inc.
Comments