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

doc concatenate until blank 1

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


arrow blue right bubble 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:

doc concatenate until blank 10

4. Then click OK, and another prompt box is popped out, please select a cell to output the concatenated result, see screenshot:

doc concatenate until blank 11

5. And then click OK button, and the column list data are concatenated between the blanks, see screenshot:

doc concatenate until blank 1


arrow blue right bubble 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:

doc concatenate until blank 3

3. Then click Ok, and a prompt box will pop out to remind you select a cell to output the result, see screenshot:

doc concatenate until blank 4

4. Click OK, and the single column data has been converted into multiple rows and columns by the blank cell, see screenshot:

doc concatenate until blank 5

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:

doc concatenate until blank 7

7. After finishing the settings, click Ok or Apply button, the cells have been concatenated into one column with a specific separator, see screenshot:

doc concatenate until blank 8

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.
kte tab 201905

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!
officetab bottom
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    JJ · 1 months ago
    It shows there's a syntax error on line 3 "Dim xRg As Range" when I'm trying to run this module based on method 1, what should I do about it?
    • To post as a guest, your comment is unpublished.
      skyyang · 1 months ago
      Hello, JJ,
      The code works well in my worksheet, which Excel version do you use?
      Or you can insert a screesnhot of your problem here.
  • To post as a guest, your comment is unpublished.
    Crystal · 3 years ago
    How would you do it if you want to base it off another column? I have similar data, but column B is a number then notes(like your fruit) in column I, I want to combine all notes in column I until there is another cell in Column B that has only number. Sometimes there are letter under B or the cells are blank which is why it needs to combine until a number.

    Then finally can it output back to where it started the combine? IE all notes for first number are in column j, but if the next number is 5 rows below that is fine, it just goes in column j but same row number as the number is found?