Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 788
Default Transpose a .csv from columns to rows

I have a .csv file that has around 700 columns, and 20 rows. I need to
transpose this and write out to a new .csv file so I can fit it into Excel,
resulting in 20 columns by 700 rows. Here is an example:

Read In:
CustID, Age, Zip, Gender
1,45,90210, M
2,30,44853,M
3,50,23456,F
4,20,23499,F

And output:
CustId,1,2,3,4
Age,45,30,50,20
Zip,90210,44853,23456,23499
Gender,M,M,F,F

Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,203
Default Transpose a .csv from columns to rows

Select all of your data, use Copy
choose where you want to place a the transposed data
The use Edit | Paste Special and click the [Transpose] box
delete what you don't want and save with a new file name.

"Chris" wrote:

I have a .csv file that has around 700 columns, and 20 rows. I need to
transpose this and write out to a new .csv file so I can fit it into Excel,
resulting in 20 columns by 700 rows. Here is an example:

Read In:
CustID, Age, Zip, Gender
1,45,90210, M
2,30,44853,M
3,50,23456,F
4,20,23499,F

And output:
CustId,1,2,3,4
Age,45,30,50,20
Zip,90210,44853,23456,23499
Gender,M,M,F,F

Thanks.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Transpose a .csv from columns to rows

Sub ABC()
Dim ff As Long, s As String
Dim l As String, rws as Long
Dim ub as Long, j as Long, lb as Long
Dim bk as Workbook
Set bk = Workbooks.Add(xlWBATWorksheet)
s = "C:\Data\testcsv.csv"
j = 1
ff = FreeFile()
Open s For Input As #ff
Do While Not EOF(ff)
Line Input #1, l
v = Split(l, ",")
ub = UBound(v)
lb = LBound(v)
rws = ub - lb + 1
bk.Worksheets(1).Cells(1, j) _
.Resize(rws, 1).Value = _
Application.Transpose(v)
j = j + 1
Loop
Close #ff
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs "C:\testcsv_trans.csv", xlCSV
Application.DisplayAlerts = True
ActiveWorkbook.Close SaveChanges:=False
End Sub

--
Regards,
Tom Ogilvy

"Chris" wrote in message
...
I have a .csv file that has around 700 columns, and 20 rows. I need to
transpose this and write out to a new .csv file so I can fit it into

Excel,
resulting in 20 columns by 700 rows. Here is an example:

Read In:
CustID, Age, Zip, Gender
1,45,90210, M
2,30,44853,M
3,50,23456,F
4,20,23499,F

And output:
CustId,1,2,3,4
Age,45,30,50,20
Zip,90210,44853,23456,23499
Gender,M,M,F,F

Thanks.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 788
Default Transpose a .csv from columns to rows

Thanks Tom! Worked like a charm.

"Tom Ogilvy" wrote:

Sub ABC()
Dim ff As Long, s As String
Dim l As String, rws as Long
Dim ub as Long, j as Long, lb as Long
Dim bk as Workbook
Set bk = Workbooks.Add(xlWBATWorksheet)
s = "C:\Data\testcsv.csv"
j = 1
ff = FreeFile()
Open s For Input As #ff
Do While Not EOF(ff)
Line Input #1, l
v = Split(l, ",")
ub = UBound(v)
lb = LBound(v)
rws = ub - lb + 1
bk.Worksheets(1).Cells(1, j) _
.Resize(rws, 1).Value = _
Application.Transpose(v)
j = j + 1
Loop
Close #ff
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs "C:\testcsv_trans.csv", xlCSV
Application.DisplayAlerts = True
ActiveWorkbook.Close SaveChanges:=False
End Sub

--
Regards,
Tom Ogilvy

"Chris" wrote in message
...
I have a .csv file that has around 700 columns, and 20 rows. I need to
transpose this and write out to a new .csv file so I can fit it into

Excel,
resulting in 20 columns by 700 rows. Here is an example:

Read In:
CustID, Age, Zip, Gender
1,45,90210, M
2,30,44853,M
3,50,23456,F
4,20,23499,F

And output:
CustId,1,2,3,4
Age,45,30,50,20
Zip,90210,44853,23456,23499
Gender,M,M,F,F

Thanks.




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 788
Default Transpose a .csv from columns to rows

Thanks for the reply, but as I said I have around 700 columns of data, which
won't fit into Excel (max columns = 256), so the "Paste Special"-Transpose
won't work.

"JLatham" wrote:

Select all of your data, use Copy
choose where you want to place a the transposed data
The use Edit | Paste Special and click the [Transpose] box
delete what you don't want and save with a new file name.

"Chris" wrote:

I have a .csv file that has around 700 columns, and 20 rows. I need to
transpose this and write out to a new .csv file so I can fit it into Excel,
resulting in 20 columns by 700 rows. Here is an example:

Read In:
CustID, Age, Zip, Gender
1,45,90210, M
2,30,44853,M
3,50,23456,F
4,20,23499,F

And output:
CustId,1,2,3,4
Age,45,30,50,20
Zip,90210,44853,23456,23499
Gender,M,M,F,F

Thanks.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,203
Default Transpose a .csv from columns to rows

I got stupid on 2 levels: didn't realize the size of the list and should have
paid attention to the fact that you'd put the question up in coding section
anyhow. Hopefully the more observant Tom Ogilvy's suggesting helped you like
you really needed.

"Chris" wrote:

Thanks for the reply, but as I said I have around 700 columns of data, which
won't fit into Excel (max columns = 256), so the "Paste Special"-Transpose
won't work.

"JLatham" wrote:

Select all of your data, use Copy
choose where you want to place a the transposed data
The use Edit | Paste Special and click the [Transpose] box
delete what you don't want and save with a new file name.

"Chris" wrote:

I have a .csv file that has around 700 columns, and 20 rows. I need to
transpose this and write out to a new .csv file so I can fit it into Excel,
resulting in 20 columns by 700 rows. Here is an example:

Read In:
CustID, Age, Zip, Gender
1,45,90210, M
2,30,44853,M
3,50,23456,F
4,20,23499,F

And output:
CustId,1,2,3,4
Age,45,30,50,20
Zip,90210,44853,23456,23499
Gender,M,M,F,F

Thanks.

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
TRANSPOSE ROWS TO COLUMNS excelhel_p Excel Discussion (Misc queries) 4 June 13th 09 08:18 AM
Transpose columns to rows using first columns repeated. hn7155 Excel Worksheet Functions 7 February 12th 09 11:50 PM
How do you transpose rows to columns? msn Excel Discussion (Misc queries) 6 September 1st 07 04:00 AM
transpose 7 rows/7 columns Annette Excel Programming 4 January 29th 06 12:17 PM
Transpose Columns to Rows Rashid Khan Excel Programming 2 June 26th 04 09:49 PM


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