Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

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


Transform a single column / row to a range by blank cells:

Kutools for Excel's Transform Range utility can help you to convert a single row or column to a range of cells and vice versa.

doc concatenate until blank 9

Kutools for Excel: with more than 200 handy Excel add-ins, free to try with no limitation in 60 days. Download and free trial Now!


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 20160513
    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 60 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:

doc concatenate until blank 2

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 > Combine, see screenshot:

doc concatenate until blank 6

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 !



Recommended Productivity Tools for Excel

Kutools for Excel Helps You Always Finish Work Ahead of Time, and Stand Out From Crowd

  • More than 300 powerful advanced features, designed for 1500 work scenarios, increasing productivity by 70%, give you more time to take care of family and enjoy life.
  • No longer need memorizing formulas and VBA codes, give your brain a rest from now on.
  • Become an Excel expert in 3 minutes, Complicated and repeated operations can be done in seconds, 
  • Reduce thousands of keyboard & mouse operations every day, say goodbye to occupational diseases now.
  • 110,000 highly effective people and 300+ world-renowned companies' choice.
  • 60-day full features free trial. 60-day money back guarantees. 2 years of free upgrade and support.

Brings Tabbed Browsing and Editing to Microsoft Office, Far More Powerful Than The Browser's Tabs

  • Office Tab is designed for Word, Excel, PowerPoint and Other Office Applications: 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!

 

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.
    Crystal · 2 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?