Anda di halaman 1dari 6

10/22/2018 Auto-Highlight the Active Row When a Cell is Selected — Excel Dashboards VBA and more

TheSmallman.com
(/)
an XL ideas Lab

Search
(/)

making Excel hum...

Home (/) Courses Models (/Models/) Native Excel (/Native-Excel/) Charts (/Charts/) Dashboards (/Dashboards/)

Infographics (/Infographics/) Modelling (/Modelling/) VBA (/Vba/) Blog (/Blog/) About (/About/)

AUTO-HIGHLIGHT THE ACTIVE ROW WHEN A CELL IS


SELECTED
June 19, 2016

Something di erent on theSmallman today - actually something di erent all together.  Since starting my Excel website and subsequent blog over 3
and a half years ago I have created over 300 pages from nancial modelling to dashboard design to unlocking Excel's scripting dictionary.  I have
writen every word myself and have drawn extensively on my posts on Ozgrid and Chandoo forums.  Today for the rst time someone else is going
to do the instructing.  The two handsome gentleman above are Kasper and Mikel.  They came to my attention through a Linkedin feed from
Modelo , the nancial modelling world championships. They hail from Denmark - a place Australians feel a close connection with as one of our
own is due to become Queen of Denmark one day.  Kasper and Mikel have created an Excel blog which draws on their passion and knowledge of
Microsoft Excel. 

On Spreadsheeto - these gentleman have a bold ambition - "create the best information about Excel you have ever read." While this is an
ambitious exercise, the guys have made a very strong start, posting countless useful blog posts on all things Excel. I wish them every success as
they build their brand and Excel consulting business.

AUTO-HIGHLIGHT THE ACTIVE ROW WHEN A CELL IS SELECTED


In this guide, you will learn how to highlight a row automatically when you (or someone else) selects a cell in a sheet. This way it is always easy for
the user to see which row is selected. This is helpful in spreadsheets that are set up with vertical entries – like a database. Be aware that this
method requires some processing power, so if your le is already having trouble running smoothly, then this might not be a sustainable feature
for you.

In this article and examples, I use Excel 2016 for Windows, but this method is also usable for you if you are running Excel 2007/2010/2013.

The General Idea


In order for this to work, we need two things:To set up a conditional formatting rule that highlights an entire row if a certain formula is true.Write a
macro that recalculates the selected cell(s) when a new selection is made.These two things are fairly straightforward. I will show you how in the
following.If you want to tag along as you progress in this guide, please download the project le here (/s/Project- le-thesmallmancom-
Spreadsheeto.xls).

Highlighting rows with conditional formatting in itself is not di cult. It is the automatic part that is tricky. Check out this guide to conditional
formatting if you are not up to speed with the fundamentals.

First, select all continuous data by selecting a cell in your data and using the shortcut ‘Ctrl + A’. In the project le, the selected range is A1:E55.

https://www.thesmallman.com/blog/2016/9/15/auto-highlight-the-active-row-when-a-cell-is-selected 1/6
10/22/2018 Auto-Highlight the Active Row When a Cell is Selected — Excel Dashboards VBA and more

Then, click the ‘Conditional Formatting’-button on the ‘Home’ tab in the ribbon.

Click ‘New Rule’ and in the following dialog box choose ‘Use a formula to determine which cells to format’.

In the formula eld, enter this formula:

=OR(CELL("row")=CELL("row",A1))

The last argument of the second ‘CELL’-function (the A1) must be the top left cell of the selected data (from before you clicked the ‘Conditional
Formatting’ button).

Customizing The Format


It is up to you whether the row is highlighted by bolding the font, changing the ll color or something entirely di erent. A word of advice, though:
Please don’t make the row stand out too much. If you color the row blood-red people will have a di cult time reading the values in the row. It will
then be tiresome and hard to nd the corresponding values in the sheet, which goes against the original purpose of the feature.

Customize your format by clicking the ‘Format…’ button in the ‘New Formatting Rule’ dialog box.

From the tabs at the top of the dialog box, choose which kind of formatting you want to apply. For this example, I have chosen a yellow ll for the
cells in the row. Then click ‘OK’.

Writing The Macro


I have written the macro for you, but it is not complicated. It simply looks like this:

Option Explicit

https://www.thesmallman.com/blog/2016/9/15/auto-highlight-the-active-row-when-a-cell-is-selected 2/6
10/22/2018 Auto-Highlight the Active Row When a Cell is Selected — Excel Dashboards VBA and more

Private Sub Worksheet_SelectionChange(ByVal Target As Range)


   Target.Calculate
End Sub

This code goes not in a normal module, but in the code belonging to a speci c worksheet. Use the shortcut ‘Alt + F11’ to get to the ‘VBA editor’.

Double click ‘Sheet2(Employees)’ in the ‘Project Explorer’ and paste the code from above. If your ‘Project Explorer’ (the menu to the left) is missing
and it does not look like the screenshot on your computer, you need to toggle on the ‘Project Explorer’. Click ‘View’ in the menu and click ‘Project
Explorer’.

Conclution
There you have it. Setting this up is quite easy and quick to do, but adds a nice touch to the system you have created if it holds data in a database
form. Test it out for yourself.

If you haven’t downloaded the project le, be sure to save your work as a macro-enabled workbook (The le type ending with .xlsm).

This guide is written by Kasper from Spreadsheeto (http://spreadsheeto.com/).

Tags Excel (/blog/?tag=Excel), Autohighlight (/blog/?tag=Autohighlight), Auto (/blog/?tag=Auto), highlight (/blog/?tag=highlight), Active (/blog/?tag=Active),
Row (/blog/?tag=Row), cell (/blog/?tag=cell), selected (/blog/?tag=selected)

Share 8 Likes

← Advanced Filter a List Automatically (/blog/2016/9/15/advanced- lter-a-l… Water Statistics Infographic in Excel → (/blog/2016/9/15/water-statistics-in…

Featured Posts

 

Evaluate and Filter Part 2


April 26, 2015
(/blog/2016/9/16/evaluate-and- lter-part-2)

Recent Posts
Protect a Worksheet, Use the Auto lter (/blog/2018/10/18/protect-a-worksheet-but-use-the-auto lter) October 18, 2018

https://www.thesmallman.com/blog/2016/9/15/auto-highlight-the-active-row-when-a-cell-is-selected 3/6
10/22/2018 Auto-Highlight the Active Row When a Cell is Selected — Excel Dashboards VBA and more

Countifs Across Sheets (/blog/2018/10/10/countifs-across-sheets) October 10, 2018

Excel VBA to Select Sheets (/blog/2018/9/21/vba-to-select-sheets) September 22, 2018

(/blog/2018/5/19/power-bi-desktop-dashboard)

Power BI Desktop Dashboard (/blog/2018/5/19/power-bi-desktop-dashboard)


August 20, 2018

(/blog/2018/8/1/new-excel-dashboard-tools)

New Excel Dashboard Tools (/blog/2018/8/1/new-excel-dashboard-tools)


August 1, 2018

(/blog/2018/6/17/watch-this-space)

Watch This Space (/blog/2018/6/17/watch-this-space)


July 11, 2018

(/blog/2018/6/3/the-fuzzy-world-of- nancial-modelling)

The Fuzzy World of Financial Modelling (/blog/2018/6/3/the-fuzzy-world-of- nancial-modelling)


May 31, 2018

https://www.thesmallman.com/blog/2016/9/15/auto-highlight-the-active-row-when-a-cell-is-selected 4/6
10/22/2018 Auto-Highlight the Active Row When a Cell is Selected — Excel Dashboards VBA and more

(/blog/2018/4/8/excel-auto ll- ll-down-to-bottom-of-range)

Excel Auto ll - Fill Down to Bottom of Range (/blog/2018/4/8/excel-auto ll- ll-down-to-bottom-of-range)


April 8, 2018

(/blog/2018/4/5/social-media-dashboard-in-excel)

Social Media Dashboard in Excel (/blog/2018/4/5/social-media-dashboard-in-excel)


April 5, 2018

(/blog/2018/3/15/range-areas-in-excel-with-vba)

Range Areas in Excel with VBA (/blog/2018/3/15/range-areas-in-excel-with-vba)


March 15, 2018

TRAINING FOLLOW US:

D a s h b o a r d i n g W i t h E x c e l ( / D a s h b o a r d i n g -W i t h - 3 St a t e m e n t M o d e l l i n g I n E xc e l ( / 3 - 
E xc e l - C o u r s e ) Statement-Financial-Modelling) (HTTPS://WWW.FA
Visual Analytics (/Visual-Analytics-Course) Project Financial Modelling (/Project-
549588165139776
A d v a n c e d D a s h b o a r d D e s i g n I n E xc e l ( / A d v a n c e d - Financial-Modelling) 
Dashboard-Design) PowerPivot (/Powerpivot)
(HTTPS://TWITTER
F i n a n c i a l M o d e l l i n g I n E xc e l ( / F i n a n c i a l - M o d e l l i n g - E xc e l Au t o m a t i o n W i t h V B A ( / E xc e l - 
I n - E xc e l - C o u r s e ) A u t o m a t i o n -W i t h -V b a )
(HTTPS://AU.PINT
A d v a n c e d F i n a n c i a l M o d e l l i n g I n E xc e l ( / A d v a n c e d - F i n a n c i a l M o d e l l i n g W i t h V B A ( / F i n a n c i a l - 
Financial-Modelling-Course) (HTTPS://WWW.LI
M o d e l l i n g -W i t h -V b a - C o u r s e )
TRK=HP-IDENTITY
marcussmall@thesmallman.com
(mailto:marcussmall@thesmallman.com

https://www.thesmallman.com/blog/2016/9/15/auto-highlight-the-active-row-when-a-cell-is-selected 5/6
10/22/2018 Auto-Highlight the Active Row When a Cell is Selected — Excel Dashboards VBA and more

 
T H E S M A L L M A N . C O M - M A K I N G YO U R S M A L L SYS T E M S H U M . . .
© COPYRIGHT THESMALLMAN.COM ALL RIGHTS RESERVED.

https://www.thesmallman.com/blog/2016/9/15/auto-highlight-the-active-row-when-a-cell-is-selected 6/6

Anda mungkin juga menyukai