PC Review


Reply
Thread Tools Rate Thread

Concatenate list of cell values into one cell

 
 
bony_tony
Guest
Posts: n/a
 
      19th Jun 2007
Hi,
I have a list of data in column A, like the following;

UAD54334
UAD54354
UAD97721
UAD31225
and so on...

I would like to merge all these values into one cell, but with |
seperating each value. ie. I would like cell B2 to display "UAD54334|
UAD54354|UAD97721|UAD31225"

The concatenate function would work fine, but I would have to quote
each cell reference from my list each time.

I'm not sure how to merge data into one cell using VBA.

Some advice would be appreciated.

Thanks
Tony

 
Reply With Quote
 
 
 
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      19th Jun 2007
Sub ABCD()
Dim rng As Range, cell1 As Range
Dim cell As Range
Set rng = Selection
Set cell1 = rng(1)
Set rng = rng.Offset(1, 0).Resize(rng.Count - 1, 1)
For Each cell In rng
cell1.Value = cell1 & "|" & cell
Next
rng.ClearContents
End Sub

Select your data an run the macro. It concatenates it into the first cell
in the selection. Will only work on a single area range one column wide with
at least two rows selected (like your example)

--
Regards,
Tom Ogilvy


"bony_tony" wrote:

> Hi,
> I have a list of data in column A, like the following;
>
> UAD54334
> UAD54354
> UAD97721
> UAD31225
> and so on...
>
> I would like to merge all these values into one cell, but with |
> seperating each value. ie. I would like cell B2 to display "UAD54334|
> UAD54354|UAD97721|UAD31225"
>
> The concatenate function would work fine, but I would have to quote
> each cell reference from my list each time.
>
> I'm not sure how to merge data into one cell using VBA.
>
> Some advice would be appreciated.
>
> Thanks
> Tony
>
>

 
Reply With Quote
 
=?Utf-8?B?TWlrZSBI?=
Guest
Posts: n/a
 
      19th Jun 2007
Try this:-

Sub stantiate()
Dim myrange As Range
With ActiveSheet
lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
Set myrange = Range("A1:A" & lastrow)
For Each c In myrange
Cells(1, 2).Value = Cells(1, 2).Value & c.Value & "|"
Next
End Sub

Works on the active worksheet.

Mike

"bony_tony" wrote:

> Hi,
> I have a list of data in column A, like the following;
>
> UAD54334
> UAD54354
> UAD97721
> UAD31225
> and so on...
>
> I would like to merge all these values into one cell, but with |
> seperating each value. ie. I would like cell B2 to display "UAD54334|
> UAD54354|UAD97721|UAD31225"
>
> The concatenate function would work fine, but I would have to quote
> each cell reference from my list each time.
>
> I'm not sure how to merge data into one cell using VBA.
>
> Some advice would be appreciated.
>
> Thanks
> Tony
>
>

 
Reply With Quote
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      19th Jun 2007
after further reading, I see you want the results in another location. So
the modification would be

Sub ABCD()
Dim rng As Range, cell1 As Range
Dim cell As Range
Set rng = Selection
Set cell1 = Range("B2")
cell1.clearcontents
For Each cell In rng
cell1.Value = cell1 & "|" & cell
Next
End Sub

--
Regards,
Tom Ogilvy


"bony_tony" wrote:

> Hi,
> I have a list of data in column A, like the following;
>
> UAD54334
> UAD54354
> UAD97721
> UAD31225
> and so on...
>
> I would like to merge all these values into one cell, but with |
> seperating each value. ie. I would like cell B2 to display "UAD54334|
> UAD54354|UAD97721|UAD31225"
>
> The concatenate function would work fine, but I would have to quote
> each cell reference from my list each time.
>
> I'm not sure how to merge data into one cell using VBA.
>
> Some advice would be appreciated.
>
> Thanks
> Tony
>
>

 
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 text cell and formula cell result GoinCrazy Microsoft Excel Worksheet Functions 4 26th Nov 2008 04:27 PM
Populate a cell if values in cell 1 and cell 2 match cell 3 and 4 tviola@wi.rr.com Microsoft Excel Programming 1 21st Aug 2008 10:13 PM
Want to be able to click on a cell and have a list box appear to give values to populate a cell Richard Zellmer Microsoft Excel Programming 2 16th Sep 2003 11:12 PM
Want to be able to click on a cell and have a list box appear to give values to populate a cell Richard Zellmer Microsoft Excel Discussion 2 16th Sep 2003 11:12 PM
Lookup = values & concatenate to correct cell location Rob Ford Microsoft Excel Worksheet Functions 2 22nd Jul 2003 04:00 PM


Features
 

Advertising
 

Newsgroups
 


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