Return the Header for the Nearest Nonzero Cell in Excel
Question details
Find the column header associated with the nonzero value closest to a specified zero cell in a row.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A table contains pasted numeric values in B14:Z14 and corresponding headers in B3:Z3. A formula elsewhere should find the nonzero value closest to C14.
- Observed behavior
- The desired result is the row-3 header for the nearest nonzero cell, ignoring zero values and choosing the leftmost cell if distances are equal.
Check that the value range and header range span the same columns and that pasted values are stored as numbers rather than text. The modern formula below requires an Excel version with LET, FILTER, and XMATCH.
Use LET and XMATCH to find the nearest nonzero header
Use this formula in modern Excel to compare column distances and return the matching header.
The formula filters out zeros, calculates the distance from C14, and returns the first header at the minimum distance. An equal-distance tie is resolved in favor of the leftmost nonzero cell.
Click an empty cell outside B14:Z14 where you want the header to appear.
In the formula bar, enter =LET(r,$B14:$Z14,h,$B$3:$Z$3,d,ABS(COLUMN(r)-COLUMN(C14)),v,r<>0,INDEX(FILTER(h,v),XMATCH(MIN(FILTER(d,v)),FILTER(d,v)))) and press Enter.
Replace $B14:$Z14 with the row of values, $B$3:$Z$3 with the aligned headers, and C14 with the zero cell to measure from.

Find the nearest nonzero header in WPS Spreadsheets
Open the workbook in WPS Spreadsheets and use an array formula to find the closest numeric nonzero value and return its column header.
- 1. Open the workbook: In WPS Spreadsheets, use Open to select the Excel workbook containing your values and headers.
- 2. Select the result cell: Click an empty cell outside the value range B14:Z14.
- 3. Enter the array formula: In the formula bar, enter =IF(SUMPRODUCT(--ISNUMBER($B14:$Z14),--($B14:$Z14<>0))=0,"",INDEX($B$3:$Z$3,1,MATCH(MIN(IF(ISNUMBER($B14:$Z14)*($B14:$Z14<>0),ABS(COLUMN($B14:$Z14)-COLUMN(C14)),1E+99)),IF(ISNUMBER($B14:$Z14)*($B14:$Z14<>0),ABS(COLUMN($B14:$Z14)-COLUMN(C14)),1E+99),0))). Press Enter, or Ctrl+Shift+Enter on Windows if your WPS version requires array-formula entry.
- 4. Adapt the ranges: In the formula bar, replace the value range, header range, and C14 target reference with those for your table. The formula returns a blank if there are no numeric nonzero values and picks the leftmost match in a tie.

Frequently Asked Questions
What happens if two nonzero cells are equally close?
The formulas return the header of the leftmost qualifying cell because the match uses the first occurrence of the minimum distance.
How do I use a different target cell?
Replace C14 in the formula with the cell you want to measure from. Keep the value and header ranges aligned to the same columns.
Why does the Excel formula return an error when the row contains only zeros?
FILTER has no qualifying values to return. Wrap the entire formula in IFERROR(formula,"") to show a blank, but note that this also hides other errors.
Can the formula use numbers pasted from another program?
Yes, if the pasted values are stored as numbers. If a value is stored as text, select the affected cells and use Excel's Convert to Number option when it is available.




