Transpose a column of numbers (1 Viewer)

TClark14

Registered User.
Local time
Today, 05:00
Joined
Sep 28, 2001
Messages
85
In column A, each cell has a number (up to around row 250). Example:
410316
425622
47634

How can I take that column of numbers and make them show up in another cell as:

410316,425622,47634,.....etc. to include all the 250+- numbers?


THANKS!

Terry
 

elbweb

Self Taught Hero
Local time
Today, 00:00
Joined
Jul 28, 2006
Messages
126
i dont think you can do that within excel because of the length or the uncertainty, and by that i mean as a function...

you can simply say =A1 & "," & A2 & "," & A3

but thats lengthy, my solution would be a very small bit of code, that would run through the whole column and put it into one string, although, im not sure the length limits of a cell in excel, can i ask why are you doing this? maybe there is a different way to accomplish the same thing?
 

TClark14

Registered User.
Local time
Today, 05:00
Joined
Sep 28, 2001
Messages
85
I actually need the numbers in that format so I can copy and paste them into another program I am using (Viewpoint) to run a query for costs on those specfic job numbers. The access database contains the job numbers I need, but does not contain costs. I have to copy and paste into viewpoint where all our accounting data is. If I go directly to viewpoint to run the query, again, it's a lengthy process where I manually have to type in each job number seperated by a comma. I hope this makes sense.
 

elbweb

Self Taught Hero
Local time
Today, 00:00
Joined
Jul 28, 2006
Messages
126
select the column you want, and.. i can't remember the specific process because im using excel 2007 now, and there is no more file/edit menus etc, but anyway, select the column you want,and you should be able to say to save it or export it as a csv file (comma seperated value) and you should get what you want.

or, if you want it simpler, select everything you want, copy and paste into word as text, and then find and replace, find a carriage return (look under the special text) and then replace it with a comma.

or there are a few other ways you can do this, you could even create a macro to do it for you and copy it to word, which wouldnt be that hard.. acctually i will look into that and see if i can come up with something for you.. but for now you see what you gotta do as far as i know
 

elbweb

Self Taught Hero
Local time
Today, 00:00
Joined
Jul 28, 2006
Messages
126
well after a little bit of work, i've got it. this is what you need to do..

in the excel document you are working with, create a new macro with a shortcut key or whatever you want it to be.

now dispite what it looks like, this is acctually very simple code, the second two parts are used so that after you run the code and the information is gathered, it is stuck in the clipboard, so all you need to do is go where you want to put the data and hit paste, and tada!

also there are two variables you may need to change, the AcRow, and AcCol state where to first start looking for row being the row to start at and col being the number of the column you first are at.

if you have any questions, feel free to ask.

after that, paste this code in for the new macro:

Code:
    Dim AcRow, AcCol As Integer
    Dim strTemp As String
    AcRow = 1 'change to which row you want it to start looking on
    AcCol = 1 'change to which column you want it to look in (A = 1)
    While Not Cells(AcRow, AcCol).Value = ""
    strTemp = strTemp & Cells(AcRow, AcCol).Value & "," 'add current cell if not empty
    AcRow = AcRow + 1
    Wend
    strTemp = Left(strTemp, Len(strTemp) - 1) 'remove ending comma

    ClipBoard_SetData (strTemp) 'function i got from the forums to send the data to the clipboard.

next you need to paste this above where the new code went

Code:
Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
Declare Function CloseClipboard Lib "User32" () As Long
Declare Function OpenClipboard Lib "User32" (ByVal hwnd As Long) As Long
Declare Function EmptyClipboard Lib "User32" () As Long
Declare Function lstrcpy Lib "kernel32" (ByVal lpString1 As Any, ByVal lpString2 As Any) As Long
Declare Function SetClipboardData Lib "User32" (ByVal wFormat As Long, ByVal hMem As Long) As Long
Declare Function GetClipboardData Lib "User32" (ByVal wFormat As Long) As Long
Declare Function GlobalSize Lib "kernel32" (ByVal hMem As Long) As Long
Public Const GHND = &H42
Public Const CF_TEXT = 1
Public Const MAXSIZE = 4096
and then last but not least, paste this below where the first code went.
Code:
Function ClipBoard_SetData(MyString As String)
    Dim hGlobalMemory As Long, lpGlobalMemory As Long
    Dim hClipMemory As Long, X As Long

    ' Allocate movable global memory.
    '-------------------------------------------
    hGlobalMemory = GlobalAlloc(GHND, Len(MyString) + 1)

    ' Lock the block to get a far pointer
    ' to this memory.
    lpGlobalMemory = GlobalLock(hGlobalMemory)

    ' Copy the string to this global memory.
    lpGlobalMemory = lstrcpy(lpGlobalMemory, MyString)

    ' Unlock the memory.
    If GlobalUnlock(hGlobalMemory) <> 0 Then
       MsgBox "Could not unlock memory location. Copy aborted."
       GoTo OutOfHere2
    End If

    ' Open the Clipboard to copy data to.
    If OpenClipboard(0&) = 0 Then
       MsgBox "Could not open the Clipboard. Copy aborted."
       Exit Function
    End If

    ' Clear the Clipboard.
    X = EmptyClipboard()

    ' Copy the data to the Clipboard.
    hClipMemory = SetClipboardData(CF_TEXT, hGlobalMemory)

OutOfHere2:

    If CloseClipboard() = 0 Then
       MsgBox "Could not close Clipboard."
    End If
End Function
 
Last edited:

shades

Registered User.
Local time
Yesterday, 23:00
Joined
Mar 25, 2002
Messages
516
elbweb said:
i dont think you can do that within excel because of the length or the uncertainty, and by that i mean as a function...

you can simply say =A1 & "," & A2 & "," & A3

but thats lengthy, my solution would be a very small bit of code, that would run through the whole column and put it into one string, although, im not sure the length limits of a cell in excel, can i ask why are you doing this? maybe there is a different way to accomplish the same thing?

Not only lengthy, but you can only include 29 concatenations in a formula.

And formulas themselves are limited to 1,024 characters. You can actually put several thousand characters in a cell, but not via formula.



You have chosen the correct (and only viable) route, VBA. Well done!
________
EXPEDITION
 
Last edited:

TClark14

Registered User.
Local time
Today, 05:00
Joined
Sep 28, 2001
Messages
85
Thank you very much. I will give these ideas a try in the morning and let you know how it goes.

THANKS!
 

TClark14

Registered User.
Local time
Today, 05:00
Joined
Sep 28, 2001
Messages
85
Thank you, it worked great. Sorry I didn't reply sooner, busy with work and home. But it did work. I used the idea of copying the column to Word, then replaced the carriage return wih a comma. Worked perfectly.

Thanks for all your help!
 

Data Cruncher

New member
Local time
Today, 14:00
Joined
May 15, 2007
Messages
7
Hello Terry,

I would probably try this:-

1) Sort your column data into numerical order (if that is how you want it to end up)
2) Copy the data and paste into Word (insert a few spare paragraph marks first and paste at the 2nd of these) and make sure the columns stay selected
3) Go to >Table>Convert>Table to text>Separate text with>Paragraph Marks>Ok [The data will still be selected, but not the additional P marks]
4) Go to >Edit>Replace>FindWhat>^p>Replace With>,>Replace All
5) The last value will have a comma at the end of it, which can be easily removed, then the line copied and pasted into Excel.

It's not really an Excel answer but it works; I use this sort of method of manipulating and editing text/data all the time.

Cheers,

Data Cruncher
Victoria, Australia
 

Maille

New member
Local time
Today, 05:00
Joined
Feb 11, 2008
Messages
2
more than one string of data

I agree with the pasting and transposing, however i have a sequential file of 200 pieces of data in 102 items per part, I need to transpose each data point into seperate rows with 102 columns, aside from writing my code out 102 times as below ant suggestions??

Sheets("Windes_Sequential").Select
Range("A31:A132").Select
Range("A132").Activate
Selection.Copy
Sheets("Windes_rows").Select
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True

Sheets("Windes_Sequential").Select
Range("A133:A234").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Windes_rows").Select
Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True

Sheets("Windes_Sequential").Select
Range("A235:A336").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Windes_rows").Select
Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
 

chergh

blah
Local time
Today, 05:00
Joined
Jun 15, 2004
Messages
1,414
Maybe something like this:

Code:
sub bleh()

dim startRow as long
dim i as long
dim wb as workbook
dim ws1 as worksheet
dim ws2 as worksheet


set wb = thisworkbook

set ws1 = wb.Sheets("Windes_Sequential")
set ws2 = wb.Sheets("Windes_rows")

startRow = 31

for i = 1 to 102

ws1.range("A" & startRow & ":A" & startRow +101).copy
ws2.range("A" & i).PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= False, Transpose:=True

startRow = startRow + 102
next i

end sub
 
Last edited:

Maille

New member
Local time
Today, 05:00
Joined
Feb 11, 2008
Messages
2
I'm clearly not a programmer!

Ya that's a bit tidier than what i came up with, thanks!

Sub SEQ_TBL()

Dim SEQRow As Long
Dim TBLRow As Long

Dim SEQCol As Long
Dim TBLCol As Long

Dim irow As Long
Dim LasrRow As Long

Dim SEQ As Worksheet



SEQRow = 31
SEQCol = 1
TBLCol = -28
TBLRow = 2


Do While SEQRow < 20000
Set SEQ = Worksheets("Windes_Sequential")
With SEQ
LastRow = SEQRow + 101


For irow = SEQRow To LastRow
.Cells(TBLRow, TBLCol + irow).Value = .Cells(irow, "A").Value

Next irow
End With

TBLRow = TBLRow + 1
SEQRow = SEQRow + 102
TBLCol = TBLCol - 102
Loop

End Sub
 

Users who are viewing this thread

Top Bottom