Select One Cell and Make Another Cell Bold

by Allen Wyatt
(last updated March 19, 2018)

9

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:

=CELL("address")="$K$5"

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.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13178) applies to Microsoft Excel 2007, 2010, and 2013.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Printing Documents in a Folder

If you want to print a group of documents at the same time there are a couple of ways you can accomplish the task. Here ...

Discover More

Printing More than One Copy

Need to print more than a single copy of a worksheet? You can do it easily by using the printing controls provided by Excel.

Discover More

Macro, while Running, Stops Excel from Responding

When running a macro, have you ever seen Excel appear to stop responding? This can be frustrating, but there are a couple ...

Discover More

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!

More ExcelTips (ribbon)

Changing Fonts in Multiple Workbooks

If you need to change fonts used in a lot of different workbooks, the task can be daunting, if you need to do it ...

Discover More

Stopping Fractions from Reducing

Enter a fraction into Excel, and you may be surprised that the program reduces the faction to its simplest form. If you ...

Discover More

Removing Borders

Need to get rid of the borders around a cell? The shortcut in this tip can make quick work of this formatting task.

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 8 - 1?

2018-11-02 06:34:04

BobC

I tried to make this more generic. To do this I copied the formatting from the original worksheet to another worksheet ("SheetXFormat"). In the SelectionChange sub i want to copy the formatting from "SheetXFormat" back to the original worksheet and then change the formatting of a cell offset from the selected cell by the appropriate amount (in my case I am changing the colour not the font).

But I cant figure out how to restore the cell formatting from the copy. In the code below, the "PasteSpecial" statement (line 3) doesn't work. It actually selects the entire sheet which I don't want to do, it then doesn't paste the copied cell formats, and by selecting the entire sheet it causes the offset cell format change (line 4) to fail. With that line commented out, the offset cell format change is succesful.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
ThisWorkbook.Worksheets("SheetXFormat").Copy
ActiveSheet.Cells.PasteSpecial xlPasteFormats
Target.Offset(rowOffset:=10, columnOffset:=5).Interior.Color = vbYellow
End Sub

Any help would be appreciated (it might also help others as I think my proposed solution is closer to the original requirement than the other solutions here).


2018-03-20 06:35:16

Willy Vanhaelen

@Ryan
For row 3 try:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Range("3:3").Font.Bold = (Target.Row = 3)
End Sub

For column D:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Range("D:D").Font.Bold = (Target.Column = 4)
End Sub

Change the row number or the column letter/number to suit your needs.


2018-03-19 07:39:05

Ryan

however, how does it change for every change in cell column or row ? For e.g. if I need certain rows to formatted to be a specific format if any of the columns in that row is selected... or the vice versa for columns where any rows in the column are selected..


2018-03-19 06:06:56

Willy Vanhaelen

Here is a one-liner that does the job equally well:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Range("C5").Font.Bold = (Target.Address = "$K$5")
End Sub


2014-07-29 19:23:00

Peter Atherton

I seem to remember that the original query stated 'Select say K5 then C5 should be bold'. This suggests that applying it to a range might be what the OP requires.

The following applies this to a range.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rngFormat As Range
Set Target = Range(Cells(2, 10), Cells(2, 10).End(xlDown))
Set rngFormat = Range(Cells(2, 3), Cells(2, 3).End(xlDown))

If Intersect(Target, ActiveCell) Is Nothing Then Exit Sub
rngFormat.Font.Bold = False
ActiveCell.Offset(0, -7).Font.Bold = True

End Sub


2014-07-28 08:04:29

Bryan

Whoops, had an errant quotation mark and lost a parenthesis. Should be:

If Not Intersect(Target, Range("K5")) Is Nothing Then


2014-07-28 08:02:49

Bryan

Why use ActiveCell when Target is already provided for you? I prefer If "Not Intersect(Target, Range("K5") Is Nothing Then" to check if a range is selected (this will work if K5 is included in a multi-cell selection as well).


2014-07-28 03:39:43

Carl Willems

You could use the Conditional formatting suggestion using =CELL("address")="$K$5"
and create a Selection_Change event for the worksheet that invokes recalculation

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Calculate
End Sub

BUT: it will trigger recalculation at every change of selection, so if you have a worksheet with a lot of formula's and data, it may drive you crazy as you may have a delay because of the recalculation whenever you move to another cell.


2014-07-26 12:31:43

Christian Boissinotte

Clay : cell C5 should to revert to however it was before

So If it was already bold, it should not be "unbold".


This Site

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.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.