Avatar of Jean-Christophe GALLAND
Jean-Christophe GALLAND
Flag for France asked on

Macro for conditional formating in Excel

Hello experts,

I have in a excel file:

-      A target value in C1
-      A table A4:D406
-      values for each row in column D. These values are sorted from lowest to greatest (so D4<D5<D6…)

I would like a macro that formats all the data in the range ‘An:Dn’ in ‘bold red’, with n being the row number where Dn<=C1

VB ScriptMicrosoft ExcelMicrosoft Office

Avatar of undefined
Last Comment
Martin Liss

8/22/2022 - Mon
Roy Cox

Why use VBA? Conditional Formatting should do that without VBA
Jean-Christophe GALLAND


It will help me learn VBScript and I can copy and paste in other files

Tom Farrar

I believe you can do this with Conditional Formatting.  Selecting Column D and using conditional formatting to look for cells <= C1.  The only disadvantage is the highlighting is only column D.  So if it is important to highlight A:D maybe this won't work.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Tom Farrar

Sorry my comment didn't see your responses.
Roy Cox

VBScript is not the same as VBA. I see no point in VBA for this, you can copy and paste formats to another workbook.

By all means learn VBA, but don't use it pointlessly.
Jean-Christophe GALLAND


If you don't want to respect my request, your choice... Always amazed that people spend more time challenging customers requests than addressing them. I know exactly what I want and I don't need to further justify. And yes, maybe VBA is the correct term

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Tom Farrar

Sure.  Think most of the experts comments are to help clarify the request.  Sometimes a question is not completely clear, or perhaps the author is not aware of other alternatives.  In your case you clear about what you want.
Martin Liss

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Martin Liss

I’m glad I was able to help.

If you expand the “Full Biography" section of my profile you’ll find links to some articles I’ve written that may interest you.

Marty - Microsoft MVP 2009 to 2017
              Experts Exchange Most Valuable Expert (MVE) 2015, 2017
              Experts Exchange Top Expert Visual Basic Classic 2012 to 2019
              Experts Exchange Top Expert VBA 2018, 2019
              Experts Exchange Distinguished Expert in Excel 2018