Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Ark
 
Posts: n/a
Default How to concatenate adjacent cells in a range without using &?

I would like to know if there is a way to concatenate multiple cells in a row
without having to use concatenate with "," or "&" ?

i.e. is there something like concatenate(A1:F1)?

  #2   Report Post  
Biff
 
Posts: n/a
Default How to concatenate adjacent cells in a range without using &?

Hi!

is there something like concatenate(A1:F1)?


No, no built in way to do that. Maybe something like that in the upcoming
version.

Here's a UDF that I found that does it: (don't know the author to
acknowledge)

Function Concatall(rng As Range) As String
Dim cell As Range
For Each cell In rng
Concatall = Concatall & cell.Text & " "
Next
End Function

Put it in a General module.

This concatenates a range and uses a space as a separator. If there are
empty cells in the range they are included in the returned string:

Suppose your range is A1:A5:

A1 = 1
A2 = empty
A3 = 3
A4 = 4
A5 = 5

The formula (using the UDF) would be:

=CONCATALL(A1:A5)

The return would be: 1<space 3 4 5

You can get rid of the spaces by using this formula:

=SUBSTITUTE(concatall(A1:A5)," ","")

The return would be: 1345

Or, you could get rid of the space AND change the separator to a comma by:

=SUBSTITUTE(TRIM(concatall(A1:A5))," ",", ")

The return would be: 1,3,4,5

Biff

"Ark" wrote in message
...
I would like to know if there is a way to concatenate multiple cells in a
row
without having to use concatenate with "," or "&" ?

i.e. is there something like concatenate(A1:F1)?



  #3   Report Post  
GRM via OfficeKB.com
 
Posts: n/a
Default How to concatenate adjacent cells in a range without using &?

Ark wrote:
I would like to know if there is a way to concatenate multiple cells in a row
without having to use concatenate with "," or "&" ?

i.e. is there something like concatenate(A1:F1)?


Yes there is a function if you prefer. Syntax is CONCATENATE(A1,B1,C1) not A1:
C1

But you'll find using & a lot quicker
  #4   Report Post  
Gord Dibben
 
Posts: n/a
Default How to concatenate adjacent cells in a range without using &?

Ark

You will have to use a User Defined Function.

Function ConCatRange(CellBlock As Range) As String
Dim Cell As Range
Dim sbuf As String
For Each Cell In CellBlock
If Len(Cell.text) 0 Then sbuf = sbuf & Cell.text & ","
Next
ConCatRange = Left(sbuf, Len(sbuf) - 1)
End Function

Usage is: =concatrange(A1:F1)

Note you can change the comma separator to a space or any combination of
deleimiter.

If you prefer, you could use a macro to do same thing.

Sub ConCat_Cells()
Dim x As Range
Dim y As Range
Dim z As Range
Dim w As String
Dim sbuf As String
On Error GoTo endit
w = InputBox("Enter the Type of De-limiter Desired")
Set z = Application.InputBox("Select Destination Cell", _
"Destination Cell", , , , , , 8)
Application.SendKeys "+{F8}"
Set x = Application.InputBox _
("Select Cells...Contiguous or Non-Contiguous", _
"Cells Selection", , , , , , 8)
For Each y In x
If Len(y.text) 0 Then sbuf = sbuf & y.text & w
Next
z = Left(sbuf, Len(sbuf) - 1)
Exit Sub
endit:
MsgBox "Nothing Selected. Please try again."
End Sub


Gord Dibben Excel MVP

On Sat, 15 Oct 2005 21:14:02 -0700, Ark wrote:

I would like to know if there is a way to concatenate multiple cells in a row
without having to use concatenate with "," or "&" ?

i.e. is there something like concatenate(A1:F1)?


  #5   Report Post  
Ron Rosenfeld
 
Posts: n/a
Default How to concatenate adjacent cells in a range without using &?

On Sat, 15 Oct 2005 21:14:02 -0700, Ark wrote:

I would like to know if there is a way to concatenate multiple cells in a row
without having to use concatenate with "," or "&" ?

i.e. is there something like concatenate(A1:F1)?


You could use a UDF.

The one below puts n Spaces between each string. It will handle a contiguous
cell range, non-contiguous cell ranges, or mixed ranges and strings as an
argument. For example:

=setstring(1,A1:D1,G1:H1,"the end")

would be a valid function call.

========================
Function SetString(SpacesBetween As Integer, _
ParamArray rg() As Variant) As String

'by Ron Rosenfeld

Dim c As Variant
Dim i As Long

For i = 0 To UBound(rg)
Select Case VarType(rg(i))
Case Is = vbArray + vbVariant
For Each c In rg(i)
SetString = SetString & Space(SpacesBetween) & Trim(c.Text)
Next
Case Is = vbString
SetString = SetString & Space(SpacesBetween) & Trim(rg(i))
End Select
Next i

SetString = Trim(SetString)

End Function
====================


--ron
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to format only a specific character or number in each cell withina range of cells Colleen Excel Worksheet Functions 1 September 12th 05 05:44 PM
Counting empty cells within a range of cells Rosehill - ExcelForums.com New Users to Excel 2 May 2nd 05 08:53 AM
automatically fill in a range of cells Maarten Excel Discussion (Misc queries) 1 April 29th 05 11:14 AM
Counting empty cells within a range of cells Rosehill - ExcelForums.com New Users to Excel 0 April 7th 05 12:47 AM
Count cells in one range based on parameters in another range dave roth Excel Worksheet Functions 2 March 29th 05 05:33 PM


All times are GMT +1. The time now is 09:52 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"