Pinterest Pixel

Highlight Alternate Rows in Selection Using Macros In Excel

Bryan
I’ve always believed Excel is more than just a grid of numbers — it’s a powerhouse of productivity if you know how to bend it to your will.
Over the years, I’ve used formulas, pivot tables, conditional formatting, and all sorts of tricks to make my data easier to read and manage.

But there’s one small thing that makes a huge visual difference: highlighting alternate rows.

I’ve always believed Excel is more than just a grid of numbers — it’s a powerhouse of productivity if you know how to bend it to your will. Over the years, I’ve used formulas, pivot tables, conditional formatting, and all sorts of tricks to make my data easier to read and manage. But there’s one small thing that makes a huge visual difference: highlighting alternate rows.

Sure, Excel has built-in table styles and conditional formatting to do this. But what if you want more control? What if you want the effect to apply only to a specific selection rather than the entire sheet? Or maybe you want it to trigger instantly without manually setting up rules each time. That’s where VBA macros come into play.

In this article, I’ll walk you through exactly how I highlight alternate rows in any selected range using a macro.

Key Takeaways:

  • Macros allow fast, one-click highlighting of alternate rows in any selected range.
  • VBA gives more control and flexibility compared to conditional formatting.
  • The “Note” style macro is quick and easy to implement.
  • RGB color-based macros allow full customization of highlight colors.
  • Save your file as .xlsm to preserve and run macros in the future.

 

Highlight Alternate Rows in Selection Using Macros In Excel | MyExcelOnline

Download excel workbookHighlight-Alternate-Rows-in-Selection.xlsm

 

Why I Chose the Macro Approach

Let’s get one thing straight — Excel’s Format as Table button and conditional formatting with formulas can absolutely highlight alternate rows. But here’s why I personally prefer the macro approach for certain projects:

  • It’s faster for ad-hoc tasks. I can select any random range, run my macro, and boom — alternate rows are highlighted instantly.
  • No hidden formatting rules. Conditional formatting sometimes creates extra rules in the background, which can bloat a file or behave unpredictably when copying data.
  • Easy customization. I can quickly tweak the macro for colors, patterns, or even apply multiple alternating colors in one go.
  • Better for non-table ranges. Sometimes I’m working on a section of a sheet that isn’t a structured table, and I just want the highlight applied temporarily.

Think of it like using a custom paintbrush rather than a pre-painted stencil — more freedom, more control.

Highlight Alternate Rows in Selection Using Macros

Setting the Stage: Preparing Excel for Macros

Before I could dive into writing code, I had to make sure Excel was set up to let me use macros. If you’ve never touched VBA before, here’s what I did:

  • Enabled the Developer Tab – I went to File → Options → Customize Ribbon and checked the “Developer” box. This gave me quick access to the VBA editor and macro tools.

Highlight Alternate Rows in Selection Using Macros In Excel

  • Checked Macro Security Settings – Under Developer → Macro Security, I ensured macros were enabled (or at least set to “Disable with Notification” so I can allow them when I need).

Highlight Alternate Rows in Selection Using Macros In Excel

  • Opened the VBA Editor – With the Developer tab ready, I hit Alt + F11 to launch the Visual Basic for Applications editor.

At this point, I had a blank slate ready for some code magic.

Write VBA Code

Here is our initial set of data:

Highlight Alternate Rows in Selection Using Macros In Excel

STEP 1: Go to Developer > Code > Visual Basic

Highlight Alternate Rows in Selection Using Macros In Excel | MyExcelOnline

STEP 2: Paste in your code and Select Save. Close the window afterwards.

Sub HighlightAlternateRowsInSelection()
Dim range As Range
For Each range In Selection.Rows
'Check if it's the alternate row by using modulo, set it to the style of note
If range.Row Mod 2 = 1 Then
range.Style = "Note"
Else
End If
Next range
End Sub

Highlight Alternate Rows in Selection Using Macros In Excel

STEP 3: Let us test it out!

Open the sheet containing the data. Go to Developer > Code > Macros

Highlight Alternate Rows in Selection Using Macros In Excel | MyExcelOnline

Make sure your data and macro are selected. Click Run.

Highlight Alternate Rows in Selection Using Macros In Excel

With just one click, the alternate rows of your selection are now highlighted!

Highlight Alternate Rows in Selection Using Macros In Excel

 

Pro Tips I’ve Learned

After using and tweaking these macros for years, here are a few lessons:

  • Screen Updating Off = Faster – For big ranges, turn off screen updating before the loop: Application.ScreenUpdating = False ‘ Your code here Application.ScreenUpdating = True
  • Undo Isn’t Built In – VBA actions can’t be undone with Ctrl+Z. If I need a safety net, I copy my sheet first.
  • Avoid Merged Cells – Merged cells mess up row-by-row formatting. If possible, unmerge before running.
  • Save as XLSM – Always save macro-enabled workbooks as .xlsm so the macro code sticks around.

 

FAQs

 

If you like this Excel tip, please share it



Highlight Alternate Rows in Selection Using Macros In Excel | MyExcelOnline


Bryan

Bryan Hong is an IT Software Developer for more than 10 years and has the following certifications: Microsoft Certified Professional Developer (MCPD): Web Developer, Microsoft Certified Technology Specialist (MCTS): Windows Applications, Microsoft Certified Systems Engineer (MCSE) and Microsoft Certified Systems Administrator (MCSA).

He is also an Amazon #1 bestselling author of 4 Microsoft Excel books and a teacher of Microsoft Excel & Office at the MyExecelOnline Academy Online Course.

See also  Add Date In Footer Using Macros In Excel

Star 30 Days - Full Access Star

One Dollar Trial

$1 Trial for 30 days!

Access for $1

Cancel Anytime

One Dollar Trial
  • Get FULL ACCESS to all our Excel & Office courses, bonuses, and support for just USD $1 today! Enjoy 30 days of learning and expert help.
  • You can CANCEL ANYTIME — no strings attached! Even if it’s on day 29, you won’t be charged again.
  • You'll get to keep all our downloadable Excel E-Books, Workbooks, Templates, and Cheat Sheets - yours to enjoy FOREVER!
  • Practice Workbooks
  • Certificates of Completion
  • 5 Amazing Bonuses
Satisfaction Guaranteed
Accepted paymend methods
Secure checkout

Get Video Training

Advance your Microsoft Excel & Office Skills with the MyExcelOnline Academy!

Dramatically Reduce Repetition, Stress, and Overtime!
Exponentially Increase Your Chances of a Promotion, Pay Raise or New Job!

Learn in as little as 5 minutes a day or on your schedule.

Learn More!

Share to...