Manually consolidating fragmented data by copying every Nth row in Excel is a tedious, error-prone struggle for busy analysts. When preparing compliance reports for standard funding sources like federal agencies or private investors, data integrity is paramount. This specialized Excel formula "grants" team members immediate efficiency by automating the merger of periodic rows into a single, cohesive string.
As a key stipulation, users must ensure the dataset maintains consistent row intervals to prevent alignment errors, a standard quality-control practice validated by leading firms like Apex Consulting. Below, we break down the exact syntax using TEXTJOIN and ROW functions to streamline your workflow.
When working with large datasets in Excel, you often encounter data structured in repeating patterns. For instance, you might have exported a report where every third row contains a specific piece of information-like an email address, a product SKU, or a transaction comment-and you need to consolidate these scattered values into a single, comma-separated string.
Manually copying and pasting these values is tedious and prone to errors. Fortunately, Excel offers several powerful ways to automate this process. Depending on your version of Excel, you can use modern dynamic array formulas, classic nested formulas, Power Query, or even a simple VBA macro. In this comprehensive guide, we will explore how to combine every Nth row into a single string using these different methods.
Imagine you have a list of contact details in Column A, where the data repeats in a cycle of three: Name, Department, and Email. You want to extract every 3rd row (the emails) starting from row 4 (the first email address) and combine them into a single cell, separated by a semicolon and space (; ).
| Row | Column A (Data) | Target Element? |
|---|---|---|
| 2 | John Doe | No (Name) |
| 3 | HR | No (Department) |
| 4 | john.doe@example.com | Yes (Email - 1st) |
| 5 | Jane Smith | No (Name) |
| 6 | IT | No (Department) |
| 7 | jane.smith@example.com | Yes (Email - 2nd) |
| 8 | Bob Johnson | No (Name) |
| 9 | Sales | No (Department) |
| 10 | bob.johnson@example.com | Yes (Email - 3rd) |
Our goal is to output a single string in another cell that looks like this:
john.doe@example.com; jane.smith@example.com; bob.johnson@example.com
If you are using Microsoft 365 or Excel 2021, you have access to dynamic arrays and the highly versatile FILTER and TEXTJOIN functions. This makes the task incredibly simple and elegant, requiring no helper columns or complex array keystrokes.
=TEXTJOIN("; ", TRUE, FILTER(A2:A10, MOD(ROW(A2:A10) - ROW(A2) + 1, 3) = 0))
Let's break down this formula from the inside out to understand how it targets every Nth row:
ROW(A2:A10) - ROW(A2) + 1: This generates a sequence of relative row numbers starting from 1.
For our range, it creates the array {1;
2;
3;
4;
5;
6;
7;
8;
9}. This ensures that no matter where your physical data starts on the sheet, the calculation treats your first data row as index 1.
MOD(..., 3): The MOD function returns the remainder of a division. We divide our relative row numbers by N (which is 3 in this case).
This returns {1;
2;
0;
1;
2;
0;
1;
2;
0}. Note that every third element yields a 0 because those index numbers (3, 6, 9) are perfectly divisible by 3.
... = 0: This evaluates our MOD array into boolean values (TRUE/FALSE). It returns {FALSE;
FALSE;
TRUE;
FALSE;
FALSE;
TRUE;
FALSE;
FALSE;
TRUE}.
FILTER(A2:A10, ...): The FILTER function extracts only the values from our target range where the boolean array is TRUE. This leaves us with just the emails: {"john.doe@example.com";
"jane.smith@example.com";
"bob.johnson@example.com"}.
TEXTJOIN("; ", TRUE, ...): Finally, TEXTJOIN takes our filtered array of emails, joins them together using a semicolon and a space ("; ") as the delimiter, and skips any empty cells (since the second argument is set to TRUE).
If your target data starts on a different offset within the cycle-for example, if you wanted to combine the Names (the 1st row in each group of 3)-you simply change the comparison value of the MOD output:
= 0 to = 1= 0 to = 2= 0 (since 3 divided by 3 has a remainder of 0)If you are using Excel 2016 or 2019, you have the TEXTJOIN function, but you do not have the FILTER function. To get around this limitation, you can use an array formula using IF instead of FILTER.
=TEXTJOIN("; ", TRUE, IF(MOD(ROW(A2:A10) - ROW(A2) + 1, 3) = 0, A2:A10, ""))
Note: Because this is an array formula in older versions of Excel, you must enter it by pressing Ctrl + Shift + Enter rather than just Enter. Excel will automatically wrap the formula in curly braces { }.
Instead of filtering the list, the IF statement checks if the row matches our Nth criteria. If it does, it returns the value from Column A. If it doesn't, it returns an empty string ("").
This generates an array of data intermingled with blanks: {""; ""; "john.doe@example.com"; ""; ""; "jane.smith@example.com"; ...}. Because TEXTJOIN's second argument is set to TRUE, it automatically ignores all those empty strings, cleanly joining only the extracted emails.
If you are working on a very old version of Excel that lacks TEXTJOIN entirely, native formulas cannot easily concatenate an arbitrary list of array elements without complex workarounds. The most reliable formula-based approach is to use a helper column to build the string incrementally.
=IF(MOD(ROW(B2)-ROW($B$2)+1, 3)=0, A2, "")
=IF(MOD(ROW(B3)-ROW($B$2)+1, 3)=0, IF(B2="", A3, B2 &
"; " &
A3), B2)
This helper formula checks if the current row is the Nth row. If it is, it appends the current cell's value to the accumulated string from the cell above. If it isn't, it simply passes down the accumulated string unchanged. The very last cell of your helper column will contain the final, fully concatenated string.
If you frequently need to combine every Nth row across multiple worksheets, writing a User Defined Function (UDF) in VBA is an incredibly robust choice. It keeps your Excel grid clean and gives you a simple, reusable formula like =CombineNth(range, nth_row, delimiter).
To add this code to your workbook:
ALT + F11 to open the VBA Editor.Insert >
Module.Function CombineEveryNth(SourceRange As Range, N As Long, Optional;
String = ", ");
String
Dim Cell;
Range
Dim Counter;
Long
Dim Result;
String
Counter = 1
For Each Cell In SourceRange
If Counter Mod N = 0 Then
If Cell.Value <> "" Then
Result = Result & Cell.Value & Delimiter
End If
End If
Counter = Counter + 1
Next Cell
' Strip the trailing delimiter
If Len(Result) > 0 Then
Result = Left(Result, Len(Result) - Len(Delimiter))
End If
CombineEveryNth = Result
End Function
Once the code is pasted, close the VBA Editor. You can now use your custom function just like any native Excel formula. In any cell, write:
=CombineEveryNth(A2:A10, 3, "; ")
This will seamlessly return the exact same concatenated string of every 3rd row, with the benefit of being readable and easy to maintain.
Disclaimer:
The documents and templates provided on this page are for informational and illustrative purposes only. They do not constitute professional, legal, or financial advice, and should not be relied upon as such. Because individual circumstances and regulatory requirements vary, these materials may not be suitable for your specific needs. We recommend consulting with a qualified professional before adapting or using any of these examples for official or commercial purposes.