Combine Cell Data to single cell between empty cells

arpirnat

New Member
Joined
Sep 22, 2015
Messages
34
Trying to find a way to combine the data in a random number of cells to a single cell. The data would combine between empty cells in column B. Example below... ideally it would only display in column C in the same row that column A has a value.
1​
ABCABC
DEF
GHI
DEF
GHI
2​
ABCABC
DEF
GHI
JKL
MNO
PQR
STU
DEF
GHI
JKL
MNO
PQR
STU
3​
ABCABC
DEF
DEF
4​
ABCABC
 

Some videos you may like

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

mrshl9898

Well-known Member
Joined
Feb 6, 2012
Messages
1,718
Try:

VBA Code:
Sub combine()

Dim sht As Worksheet
Dim LastRow As Long
Dim Rownum As Long
Dim FirstRow As Long
Dim mystr As String

Set sht = ActiveSheet
LastRow = sht.Cells(sht.Rows.Count, "B").End(xlUp).Row
Rownum = 1

Do Until Rownum > LastRow + 1
    FirstRow = Rownum
        Do Until Cells(Rownum, 2) = ""
            mystr = mystr & Cells(Rownum, 2) & Chr(13) & Chr(10)
            Rownum = Rownum + 1
        Loop
    Cells(FirstRow, 3) = Left(mystr, Len(mystr) - 1)
    Rownum = Rownum + 1
    mystr = ""
Loop

End Sub
 
Solution

Watch MrExcel Video

Forum statistics

Threads
1,127,738
Messages
5,626,606
Members
416,194
Latest member
Dhisilva_aguiar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top