LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 22,906
Default Concatenate many cells

Function ConCatRange(CellBlock As Range, Optional Delim As String = "") _
As String
'entered as =concatrange(a1:a10,"|") desired delimiter between quotes
'ignores blanks and zero cells
Dim Cell As Range
Dim sbuf As String

For Each Cell In CellBlock.Cells
If Cell.text < "" And Cell.text < 0 Then
sbuf = sbuf & Cell.text & Delim
End If
Next Cell

ConCatRange = Left(sbuf, Len(sbuf) - Len(Delim))

End Function


Gord Dibben MS Excel MVP

On Thu, 21 May 2009 18:20:14 -0700, art
wrote:

Thank you. However, I have some cells that have zero values in them Is there
a way to change the VBA code to ignore the zero values. So for example, I
want to use the formula like this,

A1 B1 C1 D1 E1
F1 G1
1.29 2.29 3.39 4.99 0 0
0

JoinString(A1:G1,", "), it should give me: 1.29, 2.29, 3.39, 4.99

And that's it, no zero values.

Thank you for your prompt response.

Art.

"Jacob Skaria" wrote:

Why not use a UDF..Launch VBE using short-key Alt+F11. Insert a module and
paste the below code..

A1= "To be"
B1 = "merged"
C1 = JoinString(A1:B1," ")


Function JoinString(varRange As Range, Optional varDelimiter As String)
Dim varTemp As Range
For Each varTemp In varRange
JoinString = JoinString & varDelimiter & varTemp
Next
If varDelimiter < vbNullString Then
JoinString = Mid(JoinString, 2)
End If
End Function

If this post helps click Yes
---------------
Jacob Skaria


"art" wrote:

Hello:

Is there any easy way to concatenate many cells to one cell. I have row from
A1:P1 with information in them. I want to connect them together in one long
string. Is there an easier way to do this, other than using the formula
concatenate and inserting each cell, or the "&" function? (it is to
cumbersome and I think excessive)

Is there a way to do it with an array or range formula?

Thanks for any help.

Art.


 
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
Concatenate N cells (where N is a worksheet value) ker_01 Excel Worksheet Functions 3 April 20th 09 11:55 PM
Concatenate group of cells HARSHAWARDHAN. S .SHASTRI[_2_] Excel Worksheet Functions 6 September 22nd 08 05:02 AM
Concatenate cells Snakeoids Excel Discussion (Misc queries) 6 July 28th 06 01:46 PM
CONCATENATE TWO DIFFERENT CELLS cs_vision Excel Worksheet Functions 10 April 27th 06 11:12 PM
how do I UN-concatenate cells julia Excel Discussion (Misc queries) 2 January 5th 05 07:45 PM


All times are GMT +1. The time now is 05:39 AM.

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

About Us

"It's about Microsoft Excel"