PC Review


Reply
Thread Tools Rate Thread

Concatenate many cells without zero's

 
 
art
Guest
Posts: n/a
 
      22nd May 2009
I had a question on how to do the following:
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)

I got a response from "Jacob Skaria":

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

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.


 
Reply With Quote
 
 
 
 
Jacob Skaria
Guest
Posts: n/a
 
      22nd May 2009
Function JoinString(varRange As Range, Optional varDelimiter As String)
Dim varTemp As Range
For Each varTemp In varRange
If varTemp <> 0 Then
JoinString = JoinString & varDelimiter & varTemp
End If
Next
If varDelimiter <> vbNullString Then
JoinString = Mid(JoinString, 2)
End If
End Function

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


"art" wrote:

> I had a question on how to do the following:
> 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)
>
> I got a response from "Jacob Skaria":
>
> 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
>
> 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.
>
>

 
Reply With Quote
 
art
Guest
Posts: n/a
 
      25th May 2009
Thanks. Can you please also modify the code so it gives you all the amount in
a number format like 9.00 and not 9?


Thanks.

Art



"Jacob Skaria" wrote:

> Function JoinString(varRange As Range, Optional varDelimiter As String)
> Dim varTemp As Range
> For Each varTemp In varRange
> If varTemp <> 0 Then
> JoinString = JoinString & varDelimiter & varTemp
> End If
> Next
> If varDelimiter <> vbNullString Then
> JoinString = Mid(JoinString, 2)
> End If
> End Function
>
> --
> If this post helps click Yes
> ---------------
> Jacob Skaria
>
>
> "art" wrote:
>
> > I had a question on how to do the following:
> > 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)
> >
> > I got a response from "Jacob Skaria":
> >
> > 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
> >
> > 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.
> >
> >

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      25th May 2009
If you've the cells to be concatenated are formatted nicely, you could use this:

Option Explicit
Function JoinString(varRange As Range, Optional varDelimiter As String)
Dim varTemp As Range
For Each varTemp In varRange.Cells
JoinString = JoinString & varDelimiter & varTemp.Text
Next varTemp
If varDelimiter <> vbNullString Then
JoinString = Mid(JoinString, Len(varDelimiter) + 1)
End If
End Function




art wrote:
>
> Thanks. Can you please also modify the code so it gives you all the amount in
> a number format like 9.00 and not 9?
>
> Thanks.
>
> Art
>
> "Jacob Skaria" wrote:
>
> > Function JoinString(varRange As Range, Optional varDelimiter As String)
> > Dim varTemp As Range
> > For Each varTemp In varRange
> > If varTemp <> 0 Then
> > JoinString = JoinString & varDelimiter & varTemp
> > End If
> > Next
> > If varDelimiter <> vbNullString Then
> > JoinString = Mid(JoinString, 2)
> > End If
> > End Function
> >
> > --
> > If this post helps click Yes
> > ---------------
> > Jacob Skaria
> >
> >
> > "art" wrote:
> >
> > > I had a question on how to do the following:
> > > 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)
> > >
> > > I got a response from "Jacob Skaria":
> > >
> > > 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
> > >
> > > 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.
> > >
> > >


--

Dave Peterson
 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      25th May 2009
I dropped your test for 0.

Option Explicit
Function JoinString(varRange As Range, Optional varDelimiter As String)
Dim varTemp As Range
For Each varTemp In varRange.Cells
if vartemp.value <> 0 then
JoinString = JoinString & varDelimiter & varTemp.Text
end if
Next varTemp
If varDelimiter <> vbNullString Then
JoinString = Mid(JoinString, Len(varDelimiter) + 1)
End If
End Function

Dave Peterson wrote:
>
> If you've the cells to be concatenated are formatted nicely, you could use this:
>
> Option Explicit
> Function JoinString(varRange As Range, Optional varDelimiter As String)
> Dim varTemp As Range
> For Each varTemp In varRange.Cells
> JoinString = JoinString & varDelimiter & varTemp.Text
> Next varTemp
> If varDelimiter <> vbNullString Then
> JoinString = Mid(JoinString, Len(varDelimiter) + 1)
> End If
> End Function
>
> art wrote:
> >
> > Thanks. Can you please also modify the code so it gives you all the amount in
> > a number format like 9.00 and not 9?
> >
> > Thanks.
> >
> > Art
> >
> > "Jacob Skaria" wrote:
> >
> > > Function JoinString(varRange As Range, Optional varDelimiter As String)
> > > Dim varTemp As Range
> > > For Each varTemp In varRange
> > > If varTemp <> 0 Then
> > > JoinString = JoinString & varDelimiter & varTemp
> > > End If
> > > Next
> > > If varDelimiter <> vbNullString Then
> > > JoinString = Mid(JoinString, 2)
> > > End If
> > > End Function
> > >
> > > --
> > > If this post helps click Yes
> > > ---------------
> > > Jacob Skaria
> > >
> > >
> > > "art" wrote:
> > >
> > > > I had a question on how to do the following:
> > > > 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)
> > > >
> > > > I got a response from "Jacob Skaria":
> > > >
> > > > 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
> > > >
> > > > 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.
> > > >
> > > >

>
> --
>
> Dave Peterson


--

Dave Peterson
 
Reply With Quote
 
art
Guest
Posts: n/a
 
      27th May 2009
Your code gives me the same results as 9.2 and not 9.20. Thanks for your help.


Art.



"Dave Peterson" wrote:

> I dropped your test for 0.
>
> Option Explicit
> Function JoinString(varRange As Range, Optional varDelimiter As String)
> Dim varTemp As Range
> For Each varTemp In varRange.Cells
> if vartemp.value <> 0 then
> JoinString = JoinString & varDelimiter & varTemp.Text
> end if
> Next varTemp
> If varDelimiter <> vbNullString Then
> JoinString = Mid(JoinString, Len(varDelimiter) + 1)
> End If
> End Function
>
> Dave Peterson wrote:
> >
> > If you've the cells to be concatenated are formatted nicely, you could use this:
> >
> > Option Explicit
> > Function JoinString(varRange As Range, Optional varDelimiter As String)
> > Dim varTemp As Range
> > For Each varTemp In varRange.Cells
> > JoinString = JoinString & varDelimiter & varTemp.Text
> > Next varTemp
> > If varDelimiter <> vbNullString Then
> > JoinString = Mid(JoinString, Len(varDelimiter) + 1)
> > End If
> > End Function
> >
> > art wrote:
> > >
> > > Thanks. Can you please also modify the code so it gives you all the amount in
> > > a number format like 9.00 and not 9?
> > >
> > > Thanks.
> > >
> > > Art
> > >
> > > "Jacob Skaria" wrote:
> > >
> > > > Function JoinString(varRange As Range, Optional varDelimiter As String)
> > > > Dim varTemp As Range
> > > > For Each varTemp In varRange
> > > > If varTemp <> 0 Then
> > > > JoinString = JoinString & varDelimiter & varTemp
> > > > End If
> > > > Next
> > > > If varDelimiter <> vbNullString Then
> > > > JoinString = Mid(JoinString, 2)
> > > > End If
> > > > End Function
> > > >
> > > > --
> > > > If this post helps click Yes
> > > > ---------------
> > > > Jacob Skaria
> > > >
> > > >
> > > > "art" wrote:
> > > >
> > > > > I had a question on how to do the following:
> > > > > 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)
> > > > >
> > > > > I got a response from "Jacob Skaria":
> > > > >
> > > > > 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
> > > > >
> > > > > 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.
> > > > >
> > > > >

> >
> > --
> >
> > Dave Peterson

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      27th May 2009
Actually, it gives you want's displayed in the cell on the worksheet. If you
change the format to show what you want, you can use that code.

If you don't want to change the cell's format, you can do the same thing in
code:

JoinString = JoinString & varDelimiter & format(varTemp.value,"0.00")

Use the format that you want--include as many decimals, leading zeros, commas,
currency symbols as you want.


art wrote:
>
> Your code gives me the same results as 9.2 and not 9.20. Thanks for your help.
>
> Art.
>
> "Dave Peterson" wrote:
>
> > I dropped your test for 0.
> >
> > Option Explicit
> > Function JoinString(varRange As Range, Optional varDelimiter As String)
> > Dim varTemp As Range
> > For Each varTemp In varRange.Cells
> > if vartemp.value <> 0 then
> > JoinString = JoinString & varDelimiter & varTemp.Text
> > end if
> > Next varTemp
> > If varDelimiter <> vbNullString Then
> > JoinString = Mid(JoinString, Len(varDelimiter) + 1)
> > End If
> > End Function
> >
> > Dave Peterson wrote:
> > >
> > > If you've the cells to be concatenated are formatted nicely, you could use this:
> > >
> > > Option Explicit
> > > Function JoinString(varRange As Range, Optional varDelimiter As String)
> > > Dim varTemp As Range
> > > For Each varTemp In varRange.Cells
> > > JoinString = JoinString & varDelimiter & varTemp.Text
> > > Next varTemp
> > > If varDelimiter <> vbNullString Then
> > > JoinString = Mid(JoinString, Len(varDelimiter) + 1)
> > > End If
> > > End Function
> > >
> > > art wrote:
> > > >
> > > > Thanks. Can you please also modify the code so it gives you all the amount in
> > > > a number format like 9.00 and not 9?
> > > >
> > > > Thanks.
> > > >
> > > > Art
> > > >
> > > > "Jacob Skaria" wrote:
> > > >
> > > > > Function JoinString(varRange As Range, Optional varDelimiter As String)
> > > > > Dim varTemp As Range
> > > > > For Each varTemp In varRange
> > > > > If varTemp <> 0 Then
> > > > > JoinString = JoinString & varDelimiter & varTemp
> > > > > End If
> > > > > Next
> > > > > If varDelimiter <> vbNullString Then
> > > > > JoinString = Mid(JoinString, 2)
> > > > > End If
> > > > > End Function
> > > > >
> > > > > --
> > > > > If this post helps click Yes
> > > > > ---------------
> > > > > Jacob Skaria
> > > > >
> > > > >
> > > > > "art" wrote:
> > > > >
> > > > > > I had a question on how to do the following:
> > > > > > 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)
> > > > > >
> > > > > > I got a response from "Jacob Skaria":
> > > > > >
> > > > > > 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
> > > > > >
> > > > > > 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.
> > > > > >
> > > > > >
> > >
> > > --
> > >
> > > Dave Peterson

> >
> > --
> >
> > Dave Peterson
> >


--

Dave Peterson
 
Reply With Quote
 
art
Guest
Posts: n/a
 
      28th May 2009
Right. Got it. But now it formats it so there is a space between each number
7 spaces. What do I have to change so there is no or only one space in
between. (really, the best should be what ever I put in the formula, like
=joinstring(A1:A10,", ") and thats it).

Thanks for your help.

Art.

"Dave Peterson" wrote:

> Actually, it gives you want's displayed in the cell on the worksheet. If you
> change the format to show what you want, you can use that code.
>
> If you don't want to change the cell's format, you can do the same thing in
> code:
>
> JoinString = JoinString & varDelimiter & format(varTemp.value,"0.00")
>
> Use the format that you want--include as many decimals, leading zeros, commas,
> currency symbols as you want.
>
>
> art wrote:
> >
> > Your code gives me the same results as 9.2 and not 9.20. Thanks for your help.
> >
> > Art.
> >
> > "Dave Peterson" wrote:
> >
> > > I dropped your test for 0.
> > >
> > > Option Explicit
> > > Function JoinString(varRange As Range, Optional varDelimiter As String)
> > > Dim varTemp As Range
> > > For Each varTemp In varRange.Cells
> > > if vartemp.value <> 0 then
> > > JoinString = JoinString & varDelimiter & varTemp.Text
> > > end if
> > > Next varTemp
> > > If varDelimiter <> vbNullString Then
> > > JoinString = Mid(JoinString, Len(varDelimiter) + 1)
> > > End If
> > > End Function
> > >
> > > Dave Peterson wrote:
> > > >
> > > > If you've the cells to be concatenated are formatted nicely, you could use this:
> > > >
> > > > Option Explicit
> > > > Function JoinString(varRange As Range, Optional varDelimiter As String)
> > > > Dim varTemp As Range
> > > > For Each varTemp In varRange.Cells
> > > > JoinString = JoinString & varDelimiter & varTemp.Text
> > > > Next varTemp
> > > > If varDelimiter <> vbNullString Then
> > > > JoinString = Mid(JoinString, Len(varDelimiter) + 1)
> > > > End If
> > > > End Function
> > > >
> > > > art wrote:
> > > > >
> > > > > Thanks. Can you please also modify the code so it gives you all the amount in
> > > > > a number format like 9.00 and not 9?
> > > > >
> > > > > Thanks.
> > > > >
> > > > > Art
> > > > >
> > > > > "Jacob Skaria" wrote:
> > > > >
> > > > > > Function JoinString(varRange As Range, Optional varDelimiter As String)
> > > > > > Dim varTemp As Range
> > > > > > For Each varTemp In varRange
> > > > > > If varTemp <> 0 Then
> > > > > > JoinString = JoinString & varDelimiter & varTemp
> > > > > > End If
> > > > > > Next
> > > > > > If varDelimiter <> vbNullString Then
> > > > > > JoinString = Mid(JoinString, 2)
> > > > > > End If
> > > > > > End Function
> > > > > >
> > > > > > --
> > > > > > If this post helps click Yes
> > > > > > ---------------
> > > > > > Jacob Skaria
> > > > > >
> > > > > >
> > > > > > "art" wrote:
> > > > > >
> > > > > > > I had a question on how to do the following:
> > > > > > > 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)
> > > > > > >
> > > > > > > I got a response from "Jacob Skaria":
> > > > > > >
> > > > > > > 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
> > > > > > >
> > > > > > > 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.
> > > > > > >
> > > > > > >
> > > >
> > > > --
> > > >
> > > > Dave Peterson
> > >
> > > --
> > >
> > > Dave Peterson
> > >

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      28th May 2009
What version of the function are you using?

What's in A1:A10?



art wrote:
>
> Right. Got it. But now it formats it so there is a space between each number
> 7 spaces. What do I have to change so there is no or only one space in
> between. (really, the best should be what ever I put in the formula, like
> =joinstring(A1:A10,", ") and thats it).
>
> Thanks for your help.
>
> Art.
>
> "Dave Peterson" wrote:
>
> > Actually, it gives you want's displayed in the cell on the worksheet. If you
> > change the format to show what you want, you can use that code.
> >
> > If you don't want to change the cell's format, you can do the same thing in
> > code:
> >
> > JoinString = JoinString & varDelimiter & format(varTemp.value,"0.00")
> >
> > Use the format that you want--include as many decimals, leading zeros, commas,
> > currency symbols as you want.
> >
> >
> > art wrote:
> > >
> > > Your code gives me the same results as 9.2 and not 9.20. Thanks for your help.
> > >
> > > Art.
> > >
> > > "Dave Peterson" wrote:
> > >
> > > > I dropped your test for 0.
> > > >
> > > > Option Explicit
> > > > Function JoinString(varRange As Range, Optional varDelimiter As String)
> > > > Dim varTemp As Range
> > > > For Each varTemp In varRange.Cells
> > > > if vartemp.value <> 0 then
> > > > JoinString = JoinString & varDelimiter & varTemp.Text
> > > > end if
> > > > Next varTemp
> > > > If varDelimiter <> vbNullString Then
> > > > JoinString = Mid(JoinString, Len(varDelimiter) + 1)
> > > > End If
> > > > End Function
> > > >
> > > > Dave Peterson wrote:
> > > > >
> > > > > If you've the cells to be concatenated are formatted nicely, you could use this:
> > > > >
> > > > > Option Explicit
> > > > > Function JoinString(varRange As Range, Optional varDelimiter As String)
> > > > > Dim varTemp As Range
> > > > > For Each varTemp In varRange.Cells
> > > > > JoinString = JoinString & varDelimiter & varTemp.Text
> > > > > Next varTemp
> > > > > If varDelimiter <> vbNullString Then
> > > > > JoinString = Mid(JoinString, Len(varDelimiter) + 1)
> > > > > End If
> > > > > End Function
> > > > >
> > > > > art wrote:
> > > > > >
> > > > > > Thanks. Can you please also modify the code so it gives you all the amount in
> > > > > > a number format like 9.00 and not 9?
> > > > > >
> > > > > > Thanks.
> > > > > >
> > > > > > Art
> > > > > >
> > > > > > "Jacob Skaria" wrote:
> > > > > >
> > > > > > > Function JoinString(varRange As Range, Optional varDelimiter As String)
> > > > > > > Dim varTemp As Range
> > > > > > > For Each varTemp In varRange
> > > > > > > If varTemp <> 0 Then
> > > > > > > JoinString = JoinString & varDelimiter & varTemp
> > > > > > > End If
> > > > > > > Next
> > > > > > > If varDelimiter <> vbNullString Then
> > > > > > > JoinString = Mid(JoinString, 2)
> > > > > > > End If
> > > > > > > End Function
> > > > > > >
> > > > > > > --
> > > > > > > If this post helps click Yes
> > > > > > > ---------------
> > > > > > > Jacob Skaria
> > > > > > >
> > > > > > >
> > > > > > > "art" wrote:
> > > > > > >
> > > > > > > > I had a question on how to do the following:
> > > > > > > > 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)
> > > > > > > >
> > > > > > > > I got a response from "Jacob Skaria":
> > > > > > > >
> > > > > > > > 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
> > > > > > > >
> > > > > > > > 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.
> > > > > > > >
> > > > > > > >
> > > > >
> > > > > --
> > > > >
> > > > > Dave Peterson
> > > >
> > > > --
> > > >
> > > > Dave Peterson
> > > >

> >
> > --
> >
> > Dave Peterson
> >


--

Dave Peterson
 
Reply With Quote
 
art
Guest
Posts: n/a
 
      28th May 2009
Oh right. Sorry, I forgot about the last part you gave me. JoinString =
JoinString & varDelimiter & format(varTemp.value,"0.00").


Thanks so much. It works great.

Thanks Dave.

Art.

"Dave Peterson" wrote:

> What version of the function are you using?
>
> What's in A1:A10?
>
>
>
> art wrote:
> >
> > Right. Got it. But now it formats it so there is a space between each number
> > 7 spaces. What do I have to change so there is no or only one space in
> > between. (really, the best should be what ever I put in the formula, like
> > =joinstring(A1:A10,", ") and thats it).
> >
> > Thanks for your help.
> >
> > Art.
> >
> > "Dave Peterson" wrote:
> >
> > > Actually, it gives you want's displayed in the cell on the worksheet. If you
> > > change the format to show what you want, you can use that code.
> > >
> > > If you don't want to change the cell's format, you can do the same thing in
> > > code:
> > >
> > > JoinString = JoinString & varDelimiter & format(varTemp.value,"0.00")
> > >
> > > Use the format that you want--include as many decimals, leading zeros, commas,
> > > currency symbols as you want.
> > >
> > >
> > > art wrote:
> > > >
> > > > Your code gives me the same results as 9.2 and not 9.20. Thanks for your help.
> > > >
> > > > Art.
> > > >
> > > > "Dave Peterson" wrote:
> > > >
> > > > > I dropped your test for 0.
> > > > >
> > > > > Option Explicit
> > > > > Function JoinString(varRange As Range, Optional varDelimiter As String)
> > > > > Dim varTemp As Range
> > > > > For Each varTemp In varRange.Cells
> > > > > if vartemp.value <> 0 then
> > > > > JoinString = JoinString & varDelimiter & varTemp.Text
> > > > > end if
> > > > > Next varTemp
> > > > > If varDelimiter <> vbNullString Then
> > > > > JoinString = Mid(JoinString, Len(varDelimiter) + 1)
> > > > > End If
> > > > > End Function
> > > > >
> > > > > Dave Peterson wrote:
> > > > > >
> > > > > > If you've the cells to be concatenated are formatted nicely, you could use this:
> > > > > >
> > > > > > Option Explicit
> > > > > > Function JoinString(varRange As Range, Optional varDelimiter As String)
> > > > > > Dim varTemp As Range
> > > > > > For Each varTemp In varRange.Cells
> > > > > > JoinString = JoinString & varDelimiter & varTemp.Text
> > > > > > Next varTemp
> > > > > > If varDelimiter <> vbNullString Then
> > > > > > JoinString = Mid(JoinString, Len(varDelimiter) + 1)
> > > > > > End If
> > > > > > End Function
> > > > > >
> > > > > > art wrote:
> > > > > > >
> > > > > > > Thanks. Can you please also modify the code so it gives you all the amount in
> > > > > > > a number format like 9.00 and not 9?
> > > > > > >
> > > > > > > Thanks.
> > > > > > >
> > > > > > > Art
> > > > > > >
> > > > > > > "Jacob Skaria" wrote:
> > > > > > >
> > > > > > > > Function JoinString(varRange As Range, Optional varDelimiter As String)
> > > > > > > > Dim varTemp As Range
> > > > > > > > For Each varTemp In varRange
> > > > > > > > If varTemp <> 0 Then
> > > > > > > > JoinString = JoinString & varDelimiter & varTemp
> > > > > > > > End If
> > > > > > > > Next
> > > > > > > > If varDelimiter <> vbNullString Then
> > > > > > > > JoinString = Mid(JoinString, 2)
> > > > > > > > End If
> > > > > > > > End Function
> > > > > > > >
> > > > > > > > --
> > > > > > > > If this post helps click Yes
> > > > > > > > ---------------
> > > > > > > > Jacob Skaria
> > > > > > > >
> > > > > > > >
> > > > > > > > "art" wrote:
> > > > > > > >
> > > > > > > > > I had a question on how to do the following:
> > > > > > > > > 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)
> > > > > > > > >
> > > > > > > > > I got a response from "Jacob Skaria":
> > > > > > > > >
> > > > > > > > > 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
> > > > > > > > >
> > > > > > > > > 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.
> > > > > > > > >
> > > > > > > > >
> > > > > >
> > > > > > --
> > > > > >
> > > > > > Dave Peterson
> > > > >
> > > > > --
> > > > >
> > > > > Dave Peterson
> > > > >
> > >
> > > --
> > >
> > > Dave Peterson
> > >

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Concatenate Cells peterh Microsoft Excel Worksheet Functions 5 16th Dec 2009 07:05 AM
Concatenate many cells art Microsoft Excel Worksheet Functions 0 19th May 2009 02:31 AM
how do I UN-concatenate cells =?Utf-8?B?anVsaWE=?= Microsoft Excel Misc 2 5th Jan 2005 07:45 PM
Re: Concatenate cells susan hayes Microsoft Excel Worksheet Functions 2 20th Oct 2004 09:53 PM
concatenate 30+ cells Mathias Microsoft Excel Worksheet Functions 7 28th Jun 2004 08:49 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:24 AM.