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
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
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
 
Upvote 0
Solution

Forum statistics

Threads
1,223,911
Messages
6,175,323
Members
452,635
Latest member
laura12345

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
Back
Top