Function Problems

How to Insert a Line Break After Every Nth Word in Excel

Muhammad TalhaMuhammad Talha Nov 10, 2026 870 views

Question details

The user needs a method to generate wrapped text by automatically inserting a newline character after a specified number of words in an Excel cell.

How to Insert a Line Break After Every Nth Word in Excel
Product
Excel
Device & OS
not provided
Scenario
Formatting text strings specifically for Graphviz DOT output, where forcing line breaks at set word intervals is necessary regardless of the string's total length.
Observed behavior
The user requires a dynamic formula solution that splits long strings of text and automatically applies line breaks (newlines) based on an exact word count.
Before you start

Ensure your version of Excel supports Dynamic Array functions like TEXTSPLIT, WRAPROWS, TOCOL, and LAMBDA, as these are required for this custom formula to work properly.

Solution 1Recommended

Use a Custom LAMBDA Function in the Name Manager

Create a reusable custom function named NewLine that combines Dynamic Array functions to split the text and join it back with a newline character at your chosen word count.

This approach uses LAMBDA to define a custom formula. It separates the text by spaces using TEXTSPLIT, organizes the words into rows with WRAPROWS based on your target count, and then joins them back together using TEXTJOIN while appending a newline character.

1
Open Name Manager

Navigate to the Formulas tab on the Excel ribbon and click on 'Name Manager' (or 'Define Name').

2
Define the New Function

Click 'New' to create a new named formula. In the 'Name' field, type exactly 'NewLine' (without quotes).

3
Input the LAMBDA Formula

In the 'Refers to' box at the bottom, paste the following formula: =LAMBDA(inTxt,wordCount,TEXTJOIN(" ",1,DROP(TOCOL(EXPAND(WRAPROWS(TEXTSPLIT(inTxt," "),wordCount,""),,wordCount+1,"\n")),-1))). Click OK and close the Name Manager.

4
Apply the Function to Your Text

Select an empty cell and type =NewLine(A1, 3) to process the text in cell A1, forcing a line break after every 3 words. You can change '3' to any other number to customize the wrap length.

Use a Custom LAMBDA Function in the Name Manager
Enable Wrap Text: For the line breaks to visibly affect the height and layout of the text inside your spreadsheet cell, ensure that you select the cell and click the 'Wrap Text' button on the Home tab.
Advanced Spreadsheets in WPS Office

Use Advanced Text Formulas Effortlessly in WPS Spreadsheet

WPS Spreadsheet fully supports advanced array functions and text manipulations, making it incredibly easy to format data, define custom LAMBDA functions, and prepare strings for external scripts.

  1. 1. Open Formula Options: Launch WPS Spreadsheet and navigate to the Formulas tab on the top ribbon.
  2. 2. Define Your Custom Formula: Select 'Name Manager' to define the NewLine custom LAMBDA formula just as you would in Excel.
  3. 3. Apply the Line Break Function: Type =NewLine(A1, 3) into your target cell to instantly process your text string.
  4. 4. Wrap the Text: Click the 'Wrap Text' icon on the Home tab to display the formatted text properly across multiple lines.
Fully compatible with Microsoft Excel's advanced array and text formulas.Easily manage named ranges and complex LAMBDA functions in a clean interface.Seamlessly handle text wrapping and data formatting for developer outputs.
microsoft office alternative - wps office

Frequently Asked Questions

Why are the line breaks not visible in my cell after using the formula?

By default, spreadsheet software does not display line breaks visually unless text wrapping is enabled. Select your formula cell, go to the Home tab, and click the 'Wrap Text' button to see the multi-line formatting.

Can I change the number of words before a line break occurs?

Yes. The custom NewLine function takes a second parameter for the word count. For example, using =NewLine(A1, 5) will break the text after every 5 words instead of 3.

Does this formula work in older versions of Excel?

No, this method relies on modern Dynamic Array functions such as LAMBDA, TEXTSPLIT, and WRAPROWS. These functions are only available in Microsoft 365, Excel for the Web, or fully updated versions of WPS Spreadsheet.

What if my source text contains irregular spacing?

The TEXTSPLIT function looks for exact space characters. If your text contains double spaces or trailing spaces, it is best to wrap your input reference in the TRIM function, such as =NewLine(TRIM(A1), 3), to ensure accurate word counts.