Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Building a string

Hi there.

I have a column of values, which is interspersed with empty cells, that
typically looks like the following:

red
green

blue
yellow


black

purple
orange


How can I build a string that looks like the following?

red,green,blue,yellow,black,purple,orange

Any ideas? - greatly appreciated.

Geoff

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Building a string

with code?

Sub BringTogether()
Dim rng as Range, cell as Range
Dim s as String
set rng = Columns(1).SpecialCells(xlConstants,xlTextValues)
for each cell in rng
s = s & trim(cell.Value) & ","
Next
s = Left(s,len(s)-1)
msgbox s
End Sub

--
Regards,
Tom Ogilvy

wrote in message
ups.com...
Hi there.

I have a column of values, which is interspersed with empty cells, that
typically looks like the following:

red
green

blue
yellow


black

purple
orange


How can I build a string that looks like the following?

red,green,blue,yellow,black,purple,orange

Any ideas? - greatly appreciated.

Geoff



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Building a string

Tom

Thankyou for your response to my problem. From my past experiences with
you I know that the solution that you offer is very eloquent. However,
I think the solution to my problem lays with a function. To this end I
have taken your code and tried to modify it. Unfortunately that is not
working too well either.

The following is my attempt so far: What I am trying to do, is run the
function with a named range (("colJ") as a parameter.

Function BringTogether(rng) As Range
Dim rng As Range, cell As Range
Dim s As String
'----Set rng = Columns(J).SpecialCells(xlConstants, xlTextValues)
Set rng = rng.SpecialCells(xlConstants, xlTextValues)
For Each cell In rng
s = s & Trim(cell.Value) & ","
Next
BringTogether = Left(s, Len(s) - 1)
End Function

Regards
Geoff


Tom Ogilvy wrote:
with code?

Sub BringTogether()
Dim rng as Range, cell as Range
Dim s as String
set rng = Columns(1).SpecialCells(xlConstants,xlTextValues)
for each cell in rng
s = s & trim(cell.Value) & ","
Next
s = Left(s,len(s)-1)
msgbox s
End Sub

--
Regards,
Tom Ogilvy

wrote in message
ups.com...
Hi there.

I have a column of values, which is interspersed with empty cells, that
typically looks like the following:

red
green

blue
yellow


black

purple
orange


How can I build a string that looks like the following?

red,green,blue,yellow,black,purple,orange

Any ideas? - greatly appreciated.

Geoff


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Building a string

Thnkyou Tom.

Your response did, of course, have the essentials of what I was after.
and using that I have come up with a UDF which will suit my purposes
just fine.
The following is what I have decided to run with:

Function BringTogether(rng As Range) As String
Dim cell As Range
Dim s As String
For Each cell In rng
If cell "" Then s = s & Trim(cell.Value) & ","
Next
BringTogether = Left(s, Len(s) - 1)
BringTogether = "(" & BringTogether & ")"
End Function

Regards
Geoff

wrote:
Tom

Thankyou for your response to my problem. From my past experiences with
you I know that the solution that you offer is very eloquent. However,
I think the solution to my problem lays with a function. To this end I
have taken your code and tried to modify it. Unfortunately that is not
working too well either.

The following is my attempt so far: What I am trying to do, is run the
function with a named range (("colJ") as a parameter.

Function BringTogether(rng) As Range
Dim rng As Range, cell As Range
Dim s As String
'----Set rng = Columns(J).SpecialCells(xlConstants, xlTextValues)
Set rng = rng.SpecialCells(xlConstants, xlTextValues)
For Each cell In rng
s = s & Trim(cell.Value) & ","
Next
BringTogether = Left(s, Len(s) - 1)
End Function

Regards
Geoff


Tom Ogilvy wrote:
with code?

Sub BringTogether()
Dim rng as Range, cell as Range
Dim s as String
set rng = Columns(1).SpecialCells(xlConstants,xlTextValues)
for each cell in rng
s = s & trim(cell.Value) & ","
Next
s = Left(s,len(s)-1)
msgbox s
End Sub

--
Regards,
Tom Ogilvy

wrote in message
ups.com...
Hi there.

I have a column of values, which is interspersed with empty cells, that
typically looks like the following:

red
green

blue
yellow


black

purple
orange


How can I build a string that looks like the following?

red,green,blue,yellow,black,purple,orange

Any ideas? - greatly appreciated.

Geoff


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
Building criteria string for Advanced Filter variable not resolvin JEFFWI Excel Discussion (Misc queries) 1 August 29th 07 07:52 PM
Building Sum by Matching String guruk Excel Discussion (Misc queries) 1 July 10th 06 12:55 PM
Help building string for Names.Add RefersTo, pls? Ed Excel Programming 10 April 7th 05 05:00 PM
Building a String based on Selected Check boxes Neily[_3_] Excel Programming 4 November 9th 04 12:54 PM
building a text string while looping though a worksheet Phillips Excel Programming 4 December 10th 03 08:31 AM


All times are GMT +1. The time now is 03:32 PM.

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"