Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Values from a range in one cell, seperated

In a range "stores" I have some values. What I want is to put all this
data in one cell, seperated by a ";" and a space. If there is only one
row filled in, that ";" should not be placed. Can anyone help? Thanks
in advance.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Values from a range in one cell, seperated

Hi,

I have these four values in a worksheet range A1:A4

Name1
Name2
Name3
Name4

I select the range of cells and run the following macro:

Sub ConcatData()
Dim myStr As String
Dim c As Range

For Each c In Selection.Cells
If Not IsEmpty(c) Then
myStr = myStr & "; " & c.Value
End If
Next c
myStr = Right(myStr, Len(myStr) - 2)
End Sub

--
Anant


"jgmiddel" wrote:

In a range "stores" I have some values. What I want is to put all this
data in one cell, seperated by a ";" and a space. If there is only one
row filled in, that ";" should not be placed. Can anyone help? Thanks
in advance.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Values from a range in one cell, seperated

A small correction:

Sub ConcatData()
Dim myStr As String
Dim c As Range

For Each c In Selection.Cells
If Not IsEmpty(c) Then
myStr = myStr & "; " & c.Value
End If
Next c
If Not myStr = "" Then
myStr = Right(myStr, Len(myStr) - 2)
End If
End Sub

--
Anant


"Anant Basant" wrote:

Hi,

I have these four values in a worksheet range A1:A4

Name1
Name2
Name3
Name4

I select the range of cells and run the following macro:

Sub ConcatData()
Dim myStr As String
Dim c As Range

For Each c In Selection.Cells
If Not IsEmpty(c) Then
myStr = myStr & "; " & c.Value
End If
Next c
myStr = Right(myStr, Len(myStr) - 2)
End Sub

--
Anant


"jgmiddel" wrote:

In a range "stores" I have some values. What I want is to put all this
data in one cell, seperated by a ";" and a space. If there is only one
row filled in, that ";" should not be placed. Can anyone help? Thanks
in advance.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Values from a range in one cell, seperated

Thanks for responding, but it doesn't work. I tested it in Excel 2007
and 2003


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Values from a range in one cell, seperated

Needs a cell to enter the results. Also you mentioned having a "stores" range.

Sub ConcatData()
Dim myStr As String
Dim c As Range
For Each c In Range("stores")
If Not IsEmpty(c) Then
myStr = myStr & "; " & c.Value
End If
Next c
If Not myStr = "" Then
myStr = Right(myStr, Len(myStr) - 2)
Range("J3").Value = myStr
End If
End Sub


Gord Dibben MS Excel MVP

On Sat, 29 Sep 2007 12:35:01 -0700, jgmiddel wrote:

Thanks for responding, but it doesn't work. I tested it in Excel 2007
and 2003




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Values from a range in one cell, seperated

Thanks, this works fine, exactly what I wanted!

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Values from a range in one cell, seperated

Thnaks a lot Gord for correcting the code.
--
Anant


"Gord Dibben" wrote:

Needs a cell to enter the results. Also you mentioned having a "stores" range.

Sub ConcatData()
Dim myStr As String
Dim c As Range
For Each c In Range("stores")
If Not IsEmpty(c) Then
myStr = myStr & "; " & c.Value
End If
Next c
If Not myStr = "" Then
myStr = Right(myStr, Len(myStr) - 2)
Range("J3").Value = myStr
End If
End Sub


Gord Dibben MS Excel MVP

On Sat, 29 Sep 2007 12:35:01 -0700, jgmiddel wrote:

Thanks for responding, but it doesn't work. I tested it in Excel 2007
and 2003



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
List cell values seperated by comma if criteria met Mike Pearson[_2_] Excel Worksheet Functions 2 June 2nd 07 10:31 PM
Find the sum of Comma Seperated Values In a Cell xcelion Excel Worksheet Functions 3 August 24th 05 07:55 AM
Sum of comma seperated values in cell(Reposting) xcelion Excel Worksheet Functions 3 August 22nd 05 01:16 PM
column values to a cell with comma seperated Raju Boine. Excel Worksheet Functions 3 July 27th 05 03:30 PM
parameter has multiple values seperated by value sbale Excel Programming 0 June 10th 05 03:37 PM


All times are GMT +1. The time now is 06:47 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"