by Allen Wyatt
(last updated March 19, 2018)
Clay wants to know if there is a way that when he selects a specific cell Excel will automatically make the contents of a different cell bold. For instance, if he selects cell K5 he would like whatever is in cell C5 to show as bold; when he leaves cell K5 (to go to a different cell), then cell C5 should to revert to however it was before selecting K5 made it bold.
In coming up with solutions, you might think you could use conditional formatting to apply the formatting ot cell C5. Theoretically, this should be easy to do; all you need to do is create a conditional formatting rule based on the following formula:
Since the CELL function, as used here, returns the address of whatever cell is selected, then whenever cell K5 is selected, the formatting in the rule (in this case, setting the cell to bold) is applied. The problem with this approach, however, is that it doesn't work well in practice.
The reason is because the CELL function is only evaluated when the worksheet is recalculated. If you just select cell K5, then the worksheet isn't recalculated, so the formula doesn't resolve to True, and the conditional format is not applied. The only way for it to work is to select cell K5, then press F9 to recalculate the worksheet, and then cell C5 will show up as bold.
The best way to go about the formatting is to use a macro, specifically one tied to the SelectionChange event for the worksheet. This event triggers every time the selected cell is changed. The following macro checks to see if cell K5 is selected. If it is, then cell C5 is bolded; if it is not, then cell C5 is "unbolded."
Private Sub Worksheet_SelectionChange(ByVal Target As Range) If ActiveCell.Address(False, False) = "K5" Then Range("C5").Font.Bold = True Else Range("C5").Font.Bold = False End If End Sub
Remember that this macro is added to the code for the sheet to which is applies—right click the worksheet tab and choose View Code. That is where the macro should be placed. Since the macro is executed every time you change what is selected in the worksheet, the "bold status" of cell C5 is continually updated.
Note that the macro effectively toggles the Bold property of the cell. Thus, if you select a cell other than K5, whatever is in cell C5 will not be bold. This doesn't apply, of course, if you do have some other conditional formatting rule defined for cell C5 that would cause it to appear as bold. In that case, the conditional format takes precedence of anything that this particular macro might do.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13178) applies to Microsoft Excel 2007, 2010, and 2013.
Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!
Want to draw attention to some information in a particular cell? Make the cell flash, on and off. Here's how you can ...Discover More
One of the most common cell alignment settings I use is the one to center across a selection. If you want to vary how ...Discover More
Cell contents and cell formatting are, in Excel, largely independent of each other. You can enter something in a cell and ...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.