I'm aware of the text-to-columns button. Can the opposite be done by selecting columns, and possibly running a macro or using a similar button?
Use the ampersand & character instead of the CONCATENATE function. The ampersand (&) calculation operator lets you join text items without having to use a function. For example, =A1 & B1 returns the same value as =CONCATENATE(A1,B1).
Opposite of CONCATENATE in Excel (splitting cells) The opposite of concatenate in Excel is splitting the contents of one cell into multiple cells. This can be done in a few different ways: Text to Columns feature.
Normally I say "Please post your code" for help/assistance writing macros, but this one is really, really simple.
Public Function ColumnsToText(rng As Range, Optional DelimitBy As String = " ") As String
'Applies on a row/partial row of data. Must be continuous cells, e.g., A1:D1.
Dim var As Variant
var = Application.Transpose(Application.Transpose(rng.Value))
ColumnsToText = Join(var, DelimitBy)
End Function
ENter it in a worksheet cell like:
=ColumnsToText(A1:F1)
Or you can specify an optional delimiter, it is a space by default, but you could use any string characters:
=ColumnsToText(A1:F1,"%")
Etc.
I was intrigued by the answer @David Zemens gave using a double transpose. His answer works well. I did found one other way to get a single row into a 1 dimensional array. Also I wanted a function that could handle a column. So here is my alternate answer.
Public Function ColumnOrRowToText(rng As Range, Optional DelimitBy As String = " ") As String
'rng must be a single row or a single column; cannot handle multiple columns or rows
Dim var As Variant
If rng.Rows.Count = 1 Then
var = Application.WorksheetFunction.Index(rng.Value, 1, 0) 'for a single row
Else
var = Application.Transpose(rng.Value) 'for a single column
End If
'var must be a 1 dimensional array
ColumnOrRowToText = Join(var, DelimitBy)
End Function
I believe the true reverse of Text-to-Columns is the formula TEXTJOIN. It will return your selected column entries into one cell in one long string separated by a delimeter that you can set on your own.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With