Formatting Issues

Highlight the Last Nonzero Value for Each Company in Excel

Huma Ashraf ChHuma Ashraf Ch Nov 18, 2026 868 views

Question details

Highlight the last nonzero numeric value in column B for each company listed in column A.

Highlight the Last Nonzero Value for Each Company in Excel
Product
Microsoft Excel
Device & OS
not provided
Scenario
A worksheet contains company names in column A and values in column B, with some blank or zero results.
Observed behavior
The desired result is one highlighted value per company: the bottommost nonzero numeric value, ignoring later blank or zero entries.
Before you start

Confirm that company names are in column A, values are in column B, and the first data row is row 2. The example covers rows 2 through 1000 and assumes row 1001 is blank; adjust these bounds to fit your data and resolve any error values in the range.

Solution 1Recommended

Use a conditional formatting formula for the last nonzero value

Use this rule when later entries for the same company may be blank or zero. Positive and negative values both qualify.

The rule checks whether the current value is numeric and nonzero, then looks for any later positive or negative value for the same company. Companies do not need to be grouped together.

1
Select the values

Select B2:B1000, starting with B2 as the active cell. Leave row 1001 blank for the formula's final look-ahead range.

2
Create a formula rule

On the Home tab, select Conditional Formatting > New Rule, then choose Use a formula to determine which cells to format.

3
Enter the formula

Enter =AND($A2<>"",ISNUMBER($B2),$B2<>0,COUNTIFS($A3:$A$1001,$A2,$B3:$B$1001,">0")+COUNTIFS($A3:$A$1001,$A2,$B3:$B$1001,"<0")=0). If your selection starts on another row, adjust the row references accordingly.

4
Choose a highlight

Select Format, choose a fill color, and click OK. Confirm that the rule applies to =$B$2:$B$1000, then save the rule.

Use a conditional formatting formula for the last nonzero value
Check company names and range: COUNTIFS treats asterisks and question marks in company names as wildcards, so this formula assumes names do not contain those characters. If you extend the selected range, update the formula's ending row and keep one blank row below the data.
Highlight values in WPS Spreadsheet

Highlight each company's last nonzero value in WPS Spreadsheet

Use a formula-based conditional formatting rule in WPS Spreadsheet to highlight the bottommost nonzero value for each company.

  1. 1. Open the workbook: Open WPS Spreadsheet and use Open to select your Excel workbook. Confirm that company names are in column A and values are in column B.
  2. 2. Select the value range: Select B2:B1000, keeping row 1001 blank. Adjust the selection and formula bounds if your data ends on a different row.
  3. 3. Add the formula rule: Choose Home > Conditional Formatting > New Rule and select the option to use a formula. Enter =AND($A2<>"",ISNUMBER($B2),$B2<>0,COUNTIFS($A3:$A$1001,$A2,$B3:$B$1001,">0")+COUNTIFS($A3:$A$1001,$A2,$B3:$B$1001,"<0")=0).
  4. 4. Apply the highlight: Choose a fill color in the rule's formatting options, confirm the rule, and save the workbook.
Highlight the last positive or negative value while ignoring later zeros and blanksOpen and save Microsoft Excel XLSX and XLS filesUse familiar spreadsheet formulas and formatting controlsWork with a free, lightweight office suite
microsoft office alternative - wps office

Frequently Asked Questions

What happens if a company's final row contains zero?

The rule skips that zero and highlights the nearest earlier nonzero numeric value for the same company. If no such value exists, nothing is highlighted for that company.

Does the formula highlight negative values?

Yes. It checks for both values greater than zero and values less than zero, so the last negative value can be highlighted.

Do the company rows need to be sorted or grouped?

No. The COUNTIFS checks all later rows in the specified range for the same company, even when other companies appear between its entries.

Why doesn't a last-occurrence-only formula highlight an earlier value?

A formula that checks only whether the current row is the company's last occurrence will not highlight an earlier value if a later company row contains zero or a blank. Use the nonzero look-ahead rule instead.

How do I extend the formatting to more rows?

In Conditional Formatting > Manage Rules, expand the Applies to range and update both ending references in the formula to the blank row immediately below your new last data row.