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

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

mrshl9898

Well-known Member
Joined
Feb 6, 2012
Messages
1,796
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,130,407
Messages
5,641,961
Members
417,249
Latest member
serrulate

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