Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 287
Default Hopefully an easy one - turning a list into a row

Hi

I am trying to convert a column of numbers into a row with separating
characters (|) inserted between each occurrence

So from this

00030707
039027258
060004239
060004882

To this

00030707|039027258|060004239|060004882

The other thing is that this column can have of any amount of numbers listed
in it.


Any ideas?

Many thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Hopefully an easy one - turning a list into a row

Adam,

Is this 'row' all in the same cell?

Mike

"Adam" wrote:

Hi

I am trying to convert a column of numbers into a row with separating
characters (|) inserted between each occurrence

So from this

00030707
039027258
060004239
060004882

To this

00030707|039027258|060004239|060004882

The other thing is that this column can have of any amount of numbers listed
in it.


Any ideas?

Many thanks

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Hopefully an easy one - turning a list into a row

Function RowThem(r As Range) As String
RowThem = ""
For Each rr In r
If RowThem = "" Then
RowThem = rr.Value
Else
RowThem = RowThem & "|" & rr.Value
End If
Next
End Function

--
Gary''s Student - gsnu200904
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Hopefully an easy one - turning a list into a row

Try

Sub Macro1()
For lngRow = 1 To Cells(Rows.Count, "A").End(xlUp).Row
strData = strData & "|" & Range("A" & lngRow)
Next
Range("B1") = Mid(strData, 3)
End Sub

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


"Adam" wrote:

Hi

I am trying to convert a column of numbers into a row with separating
characters (|) inserted between each occurrence

So from this

00030707
039027258
060004239
060004882

To this

00030707|039027258|060004239|060004882

The other thing is that this column can have of any amount of numbers listed
in it.


Any ideas?

Many thanks

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Hopefully an easy one - turning a list into a row

You didn't say where the column of data is, so I assumed A1 on down. Also,
you didn't say where you wanted the resulting string to be placed at, so I
assumed B1

Sub MakeColumnIntoRow()
Dim LastRow As Long, Destination As Range
Set Destination = Range("B1")
With ActiveSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
Destination.Value = Join(WorksheetFunction.Transpose( _
Range("A1:A" & LastRow)), "|")
End With
End Sub

--
Rick (MVP - Excel)


"Adam" wrote in message
...
Hi

I am trying to convert a column of numbers into a row with separating
characters (|) inserted between each occurrence

So from this

00030707
039027258
060004239
060004882

To this

00030707|039027258|060004239|060004882

The other thing is that this column can have of any amount of numbers
listed
in it.


Any ideas?

Many thanks




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Hopefully an easy one - turning a list into a row

I just noticed that I left out some dots (they make the ranges refer back to
the ActiveSheet. Here is the code you should use...

Sub MakeColumnIntoRow()
Dim LastRow As Long, Destination As Range
With ActiveSheet
Set Destination = .Range("B2")
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
Destination.Value = Join(WorksheetFunction.Transpose( _
.Range("A1:A" & LastRow)), "|")
End With
End Sub

Also note that this solution does not require any looping.

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
You didn't say where the column of data is, so I assumed A1 on down. Also,
you didn't say where you wanted the resulting string to be placed at, so I
assumed B1

Sub MakeColumnIntoRow()
Dim LastRow As Long, Destination As Range
Set Destination = Range("B1")
With ActiveSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
Destination.Value = Join(WorksheetFunction.Transpose( _
Range("A1:A" & LastRow)), "|")
End With
End Sub

--
Rick (MVP - Excel)


"Adam" wrote in message
...
Hi

I am trying to convert a column of numbers into a row with separating
characters (|) inserted between each occurrence

So from this

00030707
039027258
060004239
060004882

To this

00030707|039027258|060004239|060004882

The other thing is that this column can have of any amount of numbers
listed
in it.


Any ideas?

Many thanks



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Hopefully an easy one - turning a list into a row

Just a head's up.

If user has blank cells in the range, your code will produce extra
de-limiters.

Try this revision.

Function ConCatRange(CellBlock As Range) As String
'for non-contiguous cells =ccr((a1:a10,c4,c6,e1:e5))
Dim Cell As Range
Dim sbuf As String
For Each Cell In CellBlock
If Len(Cell.text) 0 Then sbuf = sbuf & Cell.text & "*|"
Next
ConCatRange = Left(sbuf, Len(sbuf) - 1)
End Function


Gord Dibben MS Excel MVP

On Wed, 23 Sep 2009 09:10:02 -0700, Gary''s Student
wrote:

Function RowThem(r As Range) As String
RowThem = ""
For Each rr In r
If RowThem = "" Then
RowThem = rr.Value
Else
RowThem = RowThem & "|" & rr.Value
End If
Next
End Function


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 287
Default Hopefully an easy one - turning a list into a row

Thanks all for your help

Both these get me what i'm after

cheers



"Gord Dibben" wrote:

Just a head's up.

If user has blank cells in the range, your code will produce extra
de-limiters.

Try this revision.

Function ConCatRange(CellBlock As Range) As String
'for non-contiguous cells =ccr((a1:a10,c4,c6,e1:e5))
Dim Cell As Range
Dim sbuf As String
For Each Cell In CellBlock
If Len(Cell.text) 0 Then sbuf = sbuf & Cell.text & "*|"
Next
ConCatRange = Left(sbuf, Len(sbuf) - 1)
End Function


Gord Dibben MS Excel MVP

On Wed, 23 Sep 2009 09:10:02 -0700, Gary''s Student
wrote:

Function RowThem(r As Range) As String
RowThem = ""
For Each rr In r
If RowThem = "" Then
RowThem = rr.Value
Else
RowThem = RowThem & "|" & rr.Value
End If
Next
End Function



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
Dependent Dropdown List - Not Easy! kditty02 Excel Worksheet Functions 2 April 16th 07 02:00 AM
Turning column contents into text list separated by a comma Kevin Rhinehart Excel Discussion (Misc queries) 1 January 16th 07 07:00 AM
Deleting or 'turning off' a list Brent Excel Discussion (Misc queries) 2 October 2nd 06 11:14 PM
Macro turning colums w/headers into list on multiple sheets MentalDrow Excel Programming 1 April 10th 06 06:32 PM
An easy one: Help with some VB funct about list and filter filo666 Excel Programming 8 December 1st 05 12:46 AM


All times are GMT +1. The time now is 12:19 AM.

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"