Function Problems

How to Sum the Last Non-Hyphen Values in Each Excel Row in WPS Office

Anum MushtaqAnum Mushtaq Nov 13, 2026 869 views

Question details

User needs a formula or VBA solution to sum the last N numeric values in each row while ignoring hyphens and other nonnumeric entries.

How to Sum the Last Non-Hyphen Values in Each Excel Row in WPS Office
Product
WPS Office Spreadsheets
Device & OS
not provided
Scenario
A worksheet has rows that mix numeric values and hyphens; the user wants to total only the last N numeric entries in each row.
Observed behavior
The desired result is a row-by-row sum of the last N numbers, with hyphens and nonnumeric cells skipped.
Before you start

Confirm the data range, such as B2:E5, and the cell holding N, such as B7. Ensure numbers are stored as numeric values, not text, and hyphens are entered as text entries.

Solution 1Recommended

Use the Excel 365 / WPS Dynamic Array Formula

Best for Excel 365 or WPS Office versions that support FILTER and TAKE; it filters out hyphens and sums the last N numeric values.

This formula assumes the numeric values are in B2:E2 and the count N is in cell $B$7. FILTER removes hyphens, TAKE keeps the last N values from the filtered row, and SUM adds them.

1
Select the result cell

Click cell F2 in the row where you want the sum.

2
Enter the dynamic array formula

Type =SUM(TAKE(FILTER(B2:E2,B2:E2<>"-"),,-$B$7)) into F2 and press Enter.

3
Fill down for other rows

Use the fill handle from F2 down through the remaining data rows.

Use the Excel 365 / WPS Dynamic Array Formula
Formula works dynamically: Excel 365 and current WPS Office versions that support dynamic arrays can return a single result without Ctrl+Shift+Enter.
Direct solution in WPS Office Spreadsheets

Sum the Last N Numeric Values Per Row with WPS Office Spreadsheets

Open your Excel workbook in WPS Office Spreadsheets, apply the recommended formula to filter out hyphens and sum the last N numeric values, and keep full compatibility with .xlsx files.

  1. 1. Open the workbook in WPS Office Spreadsheets: Launch WPS Office, click Open, and select the Excel workbook containing the rows with hyphens.
  2. 2. Locate the result cell and N cell: Click the first result cell, such as F2, and confirm the cell holding N, such as B7.
  3. 3. Enter the recommended formula: Type =SUM(TAKE(FILTER(B2:E2,B2:E2<>"-"),,-$B$7)) in F2 and press Enter if your WPS Office version supports dynamic arrays.
  4. 4. Fill the formula down: Drag the fill handle from F2 down through the remaining data rows to calculate each row's sum.
  5. 5. Save the workbook: Click Menu > Save or press Ctrl+S to save the results in .xlsx format.
Skip hyphens automatically and sum only the last N numeric entries in each row.Works with Excel 365 dynamic formulas, older array formulas, and VBA.Full compatibility with Microsoft Excel .xlsx, .xls, and .csv files.Free, lightweight WPS Office Spreadsheets interface for formula entry and fill-down.Formulas update automatically when N or the row values change.
microsoft office alternative - wps office

Frequently Asked Questions

Can I use these formulas when N is stored in another cell?

Yes. In the examples, N is stored in cell $B$7. Change $B$7 to the actual cell that contains the number of last values you want to sum, and the formula will update automatically.

Will the formula ignore text, blanks, and error values?

FILTER(B2:E2,B2:E2<>"-") removes only hyphen text entries. Blank cells are ignored by SUM, but error values in the range will still cause an error. Clean the range or wrap it with IFERROR if needed.

Does this work in older Excel versions without dynamic arrays?

For Excel 2019 and earlier, use the INDEX and LARGE array formula and confirm it with Ctrl+Shift+Enter. You can also use the VBA SumLastN function.

Why does my dynamic formula return #SPILL! or #CALC!?

If you enter the BYROW version in a range that is not empty, Excel cannot spill the results. Select only the first cell, clear the spill range, and press Enter again.

Can I calculate all rows at once instead of filling down?

Yes. In Excel 365 or WPS versions with BYROW, enter =BYROW(B2:E5,LAMBDA(a,SUM(TAKE(FILTER(a,a<>"-"),,-B7)))) in the first result cell and press Enter.