highlighting first non zero in row

jencha

New Member
Joined
Nov 10, 2017
Messages
20
Hello All, I'm hoping to highlight the first non-zero in the row of a large spreadsheet. I used =MATCH(TRUE,Q2:AO2<>0,0) to find the row number, but cannot understand how to use the row number to do conditional formatting. Any help or questions you have would be appreciated.

Jencha
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Welcome to the board.

Select your range, Q2:AO2. Click Conditional Formatting > New Rule > Use a Formula > and enter:

=COUNTIF($Q2:Q2,"<>0")=1

choose a fill color and click OK. If you want to apply this to multiple rows, just select Q2:AO100 (where 100 is your bottom row) and use the same formula.

Notice that an empty cell is not the same thing as a zero, so that can possibly cause unexpected results. If that matters, we can adjust the formula.
 
Upvote 0
Thanks so much Eric! I'm a brand new analyst who's been in a sales role for 10+ years, so I have lots to learn. I really do appreciate the help with this!

This formula seems to mostly work, but does highlight any zeros that come after the first non zero number.
 
Upvote 0
Nuts! I was hoisted upon my own petard! :banghead:

I specifically said that empty cells could cause a problem, and then I didn't catch that issue because I had an empty cell on my test sheet. Try this:

=AND(Q2<>0,COUNTIF($Q2:Q2,"<>0")=1)

Good luck with your new position!
 
Upvote 0
Thank you so much Eric, the second formula worked perfectly! If you have a moment, could you please describe the difference between the two formulas? I'm not sure I understand why one counted the trailing zeros and the other did not.

Jenny
 
Upvote 0
Hi Jenny,

The first formula, with just the COUNTIF, counts all non-zero cells starting from Q2 up to the current cell. Remember that Excel adjust the formula based on the relative position, so the range goes from $Q2:Q2 in Q2, to $Q2:R2 in R2, $Q2:S2 in S2, etc. So when the count of non-zero cells is 1, then we've found the first non-zero cell.

The problem with that is, if the count of non-zero cells is one, and the next cell is 0, then the sum of non-zero cells for that cell will also be 1, and thus be highlighted. So to avoid that, I added another condition, Q2<>0. Since your range starts at Q2, that's the equivalent of saying "The current cell must not be zero." So the logic of the first condition is the same, but that condition just prevents extra 0 cells from being highlighted.

Glad it works for you! :biggrin:
 
Upvote 0
Nuts! I was hoisted upon my own petard! :banghead:

I specifically said that empty cells could cause a problem, and then I didn't catch that issue because I had an empty cell on my test sheet. Try this:

=AND(Q2<>0,COUNTIF($Q2:Q2,"<>0")=1)

Good luck with your new position!

How can this be applies to also include the second non-zero value? So I use this for the first non-zero in the row, how can I change to the second non-zero? We use this to track customer purchases on their first two purchases.
 
Upvote 0
Welcome to the Forum!

Assuming no empty cells:

=AND(Q2<>0,COUNTIF($Q2:Q2,"<>0")>=1,COUNTIF($Q2:Q2,"<>0")<=2)
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,260
Members
452,627
Latest member
KitkatToby

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top