Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Mik Mik is offline
external usenet poster
 
Posts: 42
Default Concatenate values

I wish to Concatenate a Range of values.
The range will always be a single row, from column A:K, however the
row number could vary.
So, the range will be highlighted / selected by the user.

How, using VBA, do i copy the selected range and Concatenate to a
single cell?
I would also like a "space" between each concatenated value.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default Concatenate values

Hi

Try someting like this:

Sub ConcatenateCells()
Dim TargetRange As Range
Dim NotFirst As Boolean
Dim MyString As String

Set TargetRange = Selection
If TargetRange.Rows.Count 1 Then Exit Sub
For Each cell In TargetRange
If NotFirst Then
MyString = MyString & " " & cell.Value
Else
MyString = cell.Value
NotFirst = True
End If
Next
Range("L" & TargetRange.Row) = MyString
End Sub

Regards,
Per


On 13 Sep., 23:38, Mik wrote:
I wish to Concatenate a Range of values.
The range will always be a single row, from column A:K, however the
row number could vary.
So, the range will be highlighted / selected by the user.

How, using VBA, do i copy the selected range and Concatenate to a
single cell?
I would also like a "space" between each concatenated value.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 913
Default Concatenate values

On Sun, 13 Sep 2009 14:38:07 -0700 (PDT), Mik
wrote:

I wish to Concatenate a Range of values.
The range will always be a single row, from column A:K, however the
row number could vary.
So, the range will be highlighted / selected by the user.

How, using VBA, do i copy the selected range and Concatenate to a
single cell?
I would also like a "space" between each concatenated value.



Try this macro:

Sub test()
result = ""
For Each c In Selection
result = result & " " & c.Value
Next c
Cells(1, "L") = Trim(result)
End Sub

Hope this helps / Lars-Åle
  #4   Report Post  
Posted to microsoft.public.excel.programming
Mik Mik is offline
external usenet poster
 
Posts: 42
Default Concatenate values

On 13 Sep, 22:59, Lars-Åke Aspelin wrote:
On Sun, 13 Sep 2009 14:38:07 -0700 (PDT), Mik

wrote:
I wish to Concatenate a Range of values.
The range will always be a single row, from column A:K, however the
row number could vary.
So, the range will be highlighted / selected by the user.


How, using VBA, do i copy the selected range and Concatenate to a
single cell?
I would also like a "space" between each concatenated value.


Try this macro:

Sub test()
* *result = ""
* *For Each c In Selection
* * *result = result & " " & c.Value
* *Next c
* *Cells(1, "L") = Trim(result)
End Sub

Hope this helps / Lars-Åle




Many Thanks.
Both Worked.
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Concatenate values

Here is a non-looping method of doing this as well...

Sub ConcatenateAtoK()
On Error Resume Next
With WorksheetFunction
Range("L1").Value = .Trim(Join(.Transpose(.Transpose(Selection))))
End With
End Sub

--
Rick (MVP - Excel)


"Mik" wrote in message
...
I wish to Concatenate a Range of values.
The range will always be a single row, from column A:K, however the
row number could vary.
So, the range will be highlighted / selected by the user.

How, using VBA, do i copy the selected range and Concatenate to a
single cell?
I would also like a "space" between each concatenated value.




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
concatenate values Flint springs Excel Worksheet Functions 4 May 23rd 09 08:41 PM
Concatenate Values with VBA jlclyde Excel Discussion (Misc queries) 2 October 1st 08 07:05 PM
Concatenate values IF() Nikki Excel Worksheet Functions 21 May 12th 07 11:06 PM
Concatenate values dan Excel Worksheet Functions 2 August 14th 06 11:03 PM
Concatenate values Dan Excel Programming 2 August 14th 06 10:59 PM


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