Combining text from multiple cells into one cell with carriage return

PrimeTimeAction

New Member
Joined
Aug 1, 2018
Messages
9
I want to make macro to combine a group of data (separated by blank rows) from multiple cells in a column into one cell with carriage return (alt+enter) between each cell value. Can somebody help me with this.
see below:
blkAirV.png


[TABLE="width: 281"]
<colgroup><col><col></colgroup><tbody>[TR]
[TD][TABLE="width: 281"]
<colgroup><col><col></colgroup><tbody>[TR]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
I want to make macro to combine a group of data (separated by blank rows) from multiple cells in a column into one cell with carriage return (alt+enter) between each cell value
Is it ever possible for there to be more topics than than lines of text belonging to those topics?
 
Upvote 0
Is it ever possible for there to be more topics than than lines of text belonging to those topics?
You can ignore the above question I asked in Message #3 , I have found a solution for which it does not matter. The only thing this code requires that there be at least on line of text at minimum for each set of grouped topics.
Code:
[table="width: 500"]
[tr]
	[td]Sub ConcatTopicsLinesOfText()
  Dim X As Long, Ar As Range, RngB As Range, RngC As Range, Result As Variant
  Set RngB = Columns("B").SpecialCells(xlConstants)
  Set RngC = Columns("C").SpecialCells(xlConstants)
  ReDim Result(1 To Application.Max(RngB.Areas.Count, RngC.Areas.Count), 1 To 2)
  For Each Ar In RngB.Areas
    X = X + 1
    If Ar.Rows.Count = 1 Then
      Result(X, 1) = Ar
    Else
      Result(X, 1) = Join(Application.Transpose(Ar.Columns(1)), vbLf)
    End If
  Next
  X = 0
  For Each Ar In RngC.Areas
    X = X + 1
    If Ar.Rows.Count = 1 Then
      Result(X, 2) = Ar
    Else
      Result(X, 2) = Join(Application.Transpose(Ar.Columns(1)), vbLf)
    End If
  Next
  Range("B20").Resize(UBound(Result), 2) = Result
End Sub[/td]
[/tr]
[/table]
 
Upvote 0
You can ignore the above question I asked in Message #3 , I have found a solution for which it does not matter. The only thing this code requires that there be at least on line of text at minimum for each set of grouped topics.
Code:
[TABLE="width: 500"]
<tbody>[TR]
[TD]Sub ConcatTopicsLinesOfText()
  Dim X As Long, Ar As Range, RngB As Range, RngC As Range, Result As Variant
  Set RngB = Columns("B").SpecialCells(xlConstants)
  Set RngC = Columns("C").SpecialCells(xlConstants)
  ReDim Result(1 To Application.Max(RngB.Areas.Count, RngC.Areas.Count), 1 To 2)
  For Each Ar In RngB.Areas
    X = X + 1
    If Ar.Rows.Count = 1 Then
      Result(X, 1) = Ar
    Else
      Result(X, 1) = Join(Application.Transpose(Ar.Columns(1)), vbLf)
    End If
  Next
  X = 0
  For Each Ar In RngC.Areas
    X = X + 1
    If Ar.Rows.Count = 1 Then
      Result(X, 2) = Ar
    Else
      Result(X, 2) = Join(Application.Transpose(Ar.Columns(1)), vbLf)
    End If
  Next
  Range("B20").Resize(UBound(Result), 2) = Result
End Sub[/TD]
[/TR]
</tbody>[/TABLE]
Thanks alot for this. I think this will do the trick. I will check it out first thing in the morning.

for information, alternatively to VBA, you can use PowerQuery
I will have a look at powerquerry. Seems to be quite useful. Thanks for suggestion.
 
Upvote 0

Forum statistics

Threads
1,224,821
Messages
6,181,163
Members
453,021
Latest member
Justyna P

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