Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Dependent Dropdown List - Not Easy! | Excel Worksheet Functions | |||
Turning column contents into text list separated by a comma | Excel Discussion (Misc queries) | |||
Deleting or 'turning off' a list | Excel Discussion (Misc queries) | |||
Macro turning colums w/headers into list on multiple sheets | Excel Programming | |||
An easy one: Help with some VB funct about list and filter | Excel Programming |