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 cells ignore or skip blanks in Excel?

Excel’s Concatenate function can help you to combine multiple cell values into one cell quickly, if there are some blank cells within the selected cells, this function will combine the blanks as well. But, sometime, you just want to concatenate cells with data and skip the empty cells, how could you finish it in Excel?

Concatenate cells ignore or skip blanks with formula

Concatenate cells ignore or skip blanks with User Defined Function

Concatenate cells ignore or skip blanks with Kutools for Excel


Concatenate multiple cells ignore or skip blanks:

Kutools for Excel's Combine feature can help you to combine or concatenate multiple rows, columns or cells without losing data but skip or ignore blank cells.

doc combine skip blanks 7

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!



Supposing, I have the following cells data which populated with some blank cells, to combine the rows into one cell, you can apply a formula to solve it.

doc combine skip blanks 1

Please enter this formula into a blank cell where you want to put the concatenated result, =A1&IF(A2<>"","-"&A2,"")&IF(A3<>"","-"&A3,"")&IF(A4<>"","-"&A4,"")&IF(A5<>"","-"&A5,""), then drag the fill handle right to the cells that you want to apply this formula, and the values of rows have been combined without the blank cells as following screenshot shown:

doc combine skip blanks 2

Tips: If there are more rows need to be concatenated, you should use the IF function to join the cells, such as =A1&IF(A2<>"","-"&A2,"")&IF(A3<>"","-"&A3,"")&IF(A4<>"","-"&A4,"")&IF(A5<>"","-"&A5,"")&IF(A6<>"","-"&A6,""). The "" character in the formula can be replaced with any other delimiters that you need.


If there are multiple cells needed to be combined, the above formula will be too complex to execute, so, you can use the following User Defined Function to solve it.

1. Hold down the Alt + F11 keys in Excel, and it opens the Microsoft Visual Basic for Applications window.

2. Click Insert > Module, and paste the following macro in the Module Window.

VBA code: Concatenate cells ignore blanks:

Function Concatenatecells(ConcatArea As Range) As String
'updateby Extendoffice 20151103
  For Each n In ConcatArea: nn = IIf(n = "", nn & "", nn & n & "/"): Next
  Concatenatecells = Left(nn, Len(nn) - 1)
End Function

3. Save and close this code window, go back to the worksheet, then enter this formula: =concatenatecells(A1:A5) into a blank cell, and drag the fill handle right to the cells to apply this formula, and you will get the following result:

doc combine skip blanks 3

Tips: In the above VBA code, you can change the“/” character to any other delimiters that you need.


Excepting the boring formula and code, here, I can recommend a handy tool-Kutools for Excel, with its powerful Combine utility, you can concatenate multiple cells into one cell with no efforts.

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 value that you want to combine.

2. Click Kutools > Combine, see screenshot:

doc combine skip blanks 4

3. In the Combine Columns or Rows dialog:

  • (1.) Choose the type of cells that you want to combine, you can combine columns, combine row and combine all cells into singe cell;
  • (2.) Specify a separator for your concatenated contents;
  • (3.) Choose the location to put the result, you can put the result to top cell or bottom cell;
  • (4.) Specify how to deal with the combined cells, you can keep or delete contents from those combined cells, and you can also merge those combined cells.
  • doc combine skip blanks 5

    4. After finishing the settings, click Ok button, and the selected rows have been combined into one cell separately, and it has skipped the blanks automatically, see screenshot:

    doc combine skip blanks 6

    Click to know more details about this Combine feature…

    Download and free trial Kutools for Excel Now !


    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!


    Recommended Productivity Tools

    Ribbon of Excel (with Kutools for Excel installed)

    300+ Advanced Features Increase Your Productivity by 71%, and Help You To Stand Out From Crowd!

    Would you like to complete your daily work quickly and perfectly? Kutools For Excel brings 300+ cool and powerful advanced features (Combine workbooks, sum by color, split cell contents, convert date, and so on...) for 1500+ work scenarios, helps you solve 82% Excel problems.

    •  Deal with all complicated tasks in seconds, help to enhance your work ability, get success from the fierce competition, and never worry about being fired.
    •  Save a lot of work time, leave much time for you to love and care the family and enjoy a comfortable life now.
    •  Reduce thousands of keyboard and mouse clicks every day, relieve your tired eyes and hands, and give you a healthy body.
    •  Become an Excel expert in 3 minutes, and get admiring glance from your colleagues or friends.
    •  No longer need to remember any painful formulas and VBA codes, have a relaxing and pleasant mind, give you a thrill you've never had before.
    •  Spend only $39, but worth than $4000 training of others. Being used by 110,000 elites and 300+ well-known companies.
    •  60-day unlimited free trial. 60-day money back guarantee. Free upgrade and support for 2 years. Buy once, use forever.
    •  Change the way you work now, and give you a better life immediately!

    Office Tab Brings Efficient And Handy Tabs to Office (include Excel), Just Like Chrome, Firefox, And New IE

    • Increases your productivity by 50% when viewing and editing multiple documents.
    • Reduce hundreds of mouse clicks for you every day, say goodbye to mouse hand.
    • Open and create documents in new tabs of same window, rather than in new windows.
    • Help you work faster and easily stand out from the crowd! One second to switch between dozens of open documents!
    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.
      Melinda · 3 months ago
      Hi, used the macro and changed the "/" to a comma "," but got a lot of commas and it appeared to add all the blank cells.
      I am doing a nested if statement to determine the appropriate sorting in the database. Is this enough to make the blank cell 'active' so that the macro sees this and adds it to the text string? How to work around that?
      thanks much
      • To post as a guest, your comment is unpublished.
        skyyang · 3 months ago
        Hello, Melinda,
        the above vba code works well in my worksheet, you just need to change the separator / to comma as below:

        Function Concatenatecells(ConcatArea As Range) As String
        'updateby Extendoffice 20151103
        For Each n In ConcatArea: nn = IIf(n = "", nn & "", nn & n & ","): Next
        Concatenatecells = Left(nn, Len(nn) - 1)
        End Function

        and then apply this formula:=concatenatecells(A1:A5)
        • To post as a guest, your comment is unpublished.
          Melinda · 3 months ago
          thanks!
          I found my problem was in the logic statement that I used to select data for these cells that I was trying to text string. I used a " " instead of "" for the false statement. That was picked up by the macro and used as a space bar and came out , , , , , text, , , ,
          So I went back and took out the space and just have the "" and then the macro worked great.
          Of course I am learning macros so that's another adventure.
          thanks much!!
    • To post as a guest, your comment is unpublished.
      Adri · 8 months ago
      Thank you, it was very helpful!
    • To post as a guest, your comment is unpublished.
      Lize-marie van Onselen · 11 months ago
      Please help, i dont always have a value in my first column, that couses that I end up with a seperator infort of the final result. Is there a way around this?
    • To post as a guest, your comment is unpublished.
      sindre · 1 years ago
      Thank you! This saved hours of frustration on my part! Works as a charm!
    • To post as a guest, your comment is unpublished.
      Par · 2 years ago
      The VBA script is wrong, because the output of the formula puts a huge space between the delimiters.