How to concatenate cell values until if finds a blank cell in a column?

For example, I have a list of values which including some blank cells, and now, I want to concatenate each set of data between blanks into a cell and list the combined values in another column as following screenshot shown. How could I concatenate cells until find a blank cell in a column?
Concatenate cell values until if finds a blank cell in a column with VBA code
Concatenate cell values until if finds a blank cell in a column with Kutools for Excel
Concatenate cell values until if finds a blank cell in a column with VBA code
There is no direct way for you to concatenate a set of cells between blanks, but, you can apply the following VBA code to deal with it. Please do as follows:
1. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.
2. Click Insert > Module, and paste the following code in the Module Window.
VBA code: concatenate cell values until if finds a blank cell
Sub Concatenatecells() 'updateby Extendoffice Dim xRg As Range Dim xSaveToRg As Range Dim xTxt As String Dim xCell As Range Dim xTStr As String On Error Resume Next xTxt = ActiveWindow.RangeSelection.Address Set xRg = Application.InputBox("Please selecte the data range:", "Kutools for Excel", xTxt, , , , , 8) If xRg Is Nothing Then Exit Sub If xRg.Columns.Count > 1 Then MsgBox "the selected range is more than one column", vbInformation, "Kutools for Ecel" Exit Sub End If Set xSaveToRg = Application.InputBox("Please selecte output cell:", "Kutools for Excel", , , , , , 8) If xSaveToRg Is Nothing Then Exit Sub Set xSaveToRg = xSaveToRg.Cells(1) Application.ScreenUpdating = False For Each xCell In xRg If xCell <> "" Then xTStr = xTStr & xCell & " " Else xSaveToRg.Value = xTStr Set xSaveToRg = xSaveToRg.Offset(1) xTStr = "" End If Next If xTStr <> "" Then xSaveToRg.Value = Left(xTStr, Len(xTStr) - 1) Application.ScreenUpdating = True End Sub
3. Then press F5 key to run this code, and a prompt box is popped out to remind you select the data range that you want to concatenate, see screenshot:
4. Then click OK, and another prompt box is popped out, please select a cell to output the concatenated result, see screenshot:
5. And then click OK button, and the column list data are concatenated between the blanks, see screenshot:
Concatenate cell values until if finds a blank cell in a column with Kutools for Excel
If you have Kutools for Excel, combining its Transform Range and Combine features, you can also finish this job as soon as possible. The Transform Range utility can help you to convert the single column to a range, and the Combine feature can help you to concatenate the transformed range to a column.
Kutools for Excel : with more than 300 handy Excel add-ins, free to try with no limitation in 30 days. |
After installing Kutools for Excel, please do as follows:
1. Select the cells that you want to concatenate, and click Kutools > Range > Transform Range, see screenshot:
2. In the Transform Range dialog box, check Single column to range option under the Transform type, and then select Blank cell delimits records under the Rows per record, see screenshot:
3. Then click Ok, and a prompt box will pop out to remind you select a cell to output the result, see screenshot:
4. Click OK, and the single column data has been converted into multiple rows and columns by the blank cell, see screenshot:
5. The converted data is in multiple columns, so you need to combine them into one column, please select the data range and click Kutools > Merge & Split > Combine Rows, Columns or Cells without Losing Data, see screenshot:
6. In the Combine Columns or Rows dialog box, do the following options:
(1.) Select Combine columns option from the To combine selected cells according to following options;
(2.) Then specify a separator that you want to separate the concatenated values;
(3.) Select how you want to deal with the combined cells. You can keep or delete the original data, and you can also merge the combined cells. See screenshot:
7. After finishing the settings, click Ok or Apply button, the cells have been concatenated into one column with a specific separator, see screenshot:
Download and free trial Kutools for Excel Now !
The Best Office Productivity Tools
Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%
- Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
- Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
- Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
- Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
- Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
- Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
- Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
- Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
- More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial. 60-day money back guarantee.

Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier
- Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
- Open and create multiple documents in new tabs of the same window, rather than in new windows.
- Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
