Function Problems

Add Text Before the First and After the Last Positive Value in Excel

Camila MilosovichCamila Milosovich Dec 2, 2026 869 views

Question details

Add text before the first positive value and after the last positive value in a range, without changing the intervening zeros.

Add Text Before the First and After the Last Positive Value in Excel
Product
Microsoft Excel
Device & OS
not provided
Scenario
A user wants to identify the first and last values greater than zero in a column and add text to those values.
Observed behavior
The first positive value should have a text prefix, the last positive value should have a text suffix, and zeros between them should remain unchanged.
Before you start

Identify the numeric range and choose an empty adjacent column for the results. The example uses A2:A10; adjust the references to match your data.

Solution 1Recommended

Use a Helper Column to Add Text to the First and Last Positive Values

Use COUNTIF to locate the first and last positive values and add the desired text without altering zeros.

The formula adds the prefix and suffix to the same value if the range contains only one positive number. If there are no positive numbers, the numeric values are returned unchanged.

1
Select an output cell

Click B2 next to the first value in the numeric range A2:A10.

2
Enter the formula

Enter =IF(A2>0,IF(COUNTIF($A$2:A2,">0")=1,"Before ","")&A2&IF(COUNTIF(A2:$A$10,">0")=1," After",""),A2) and press Enter. Replace "Before " and " After" with your preferred text.

3
Fill the formula down

Drag the fill handle from B2 down to B10. Check that the first positive value has the prefix, the last has the suffix, and zeros remain unchanged.

Use a Helper Column to Add Text to the First and Last Positive Values
Text values in the result: The positive values with added text become text rather than numbers in the output column. Keep the original numeric column if you need to use those values in calculations.
Work with spreadsheet formulas

Add Text to Positive Values in WPS Spreadsheet

Use the same COUNTIF formula in WPS Spreadsheet to label the first and last positive values while leaving zeros unchanged.

  1. 1. Open your spreadsheet: Open the workbook in WPS Spreadsheet and identify the numeric range, such as A2:A10.
  2. 2. Enter the formula: Click B2 and enter =IF(A2>0,IF(COUNTIF($A$2:A2,">0")=1,"Before ","")&A2&IF(COUNTIF(A2:$A$10,">0")=1," After",""),A2). Replace the example text and range references as needed.
  3. 3. Fill and check the results: Drag the fill handle from B2 through B10, then check the labels and zeros in column B.
Identify the first and last positive values with a formulaKeep intervening zeros unchanged in the outputOpen and edit Microsoft Excel XLSX and XLS filesUse a familiar spreadsheet interface for formulas and fill operations
microsoft office alternative - wps office

Frequently Asked Questions

What happens if there is only one positive value?

The formula adds both the prefix and the suffix to that value because it is both the first and last positive value in the range.

Will zeros or negative values change?

No. For a numeric range, the formula returns zeros and negative values unchanged in the output column.

How do I use the formula for a longer range?

Replace A2:A10 with your actual range in the formula. For example, for A2:A100, change $A$10 to $A$100 and fill the formula down to the corresponding output row.

Can I calculate with the labeled positive values?

Values combined with text are returned as text. Use the original numeric cells for calculations, or keep a separate numeric column alongside the labeled results.