Solved

one column into diffrent rows

Posted on 2003-11-25
2
247 Views
Last Modified: 2010-05-03
Hi,
I have a "file1.csv" that has 1 column which has 10 values (rows).Now I want a VB prg to read file1.csv and make the 10 rows as 1 row and 10 columns(transposing).I need thi sin loop as I have to do transposing for 5000 CSV files.
Pls help asap,
Maha
0
Comment
Question by:mahalakshmi_s
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 28

Expert Comment

by:vinnyd79
ID: 9820149
If you add a FileListbox you can loop through it and write each file to a new file.This will create a new file with the prefix "new" in front of each filename:

Private Sub Form_Load()
File1.Pattern = "*.csv"
File1.Path = "C:\Somefolder"
End Sub

Private Sub Command1_Click()
Dim i As Integer, ff As Integer, tf As Integer
Dim Ln As String, TmpStr As String
Dim origFile As String, newFile As String
For i = 0 To File1.ListCount - 1

If Right$(App.Path, 1) <> "\" Then
    origFile = File1.Path & "\" & File1.FileName
    newFile = File1.Path & "\new" & File1.FileName
Else
    origFile = File1.Path & File1.FileName
    newFile = File1.Path & "new" & File1.FileName
End If

ff = FreeFile
Open origFile For Input As #ff
tf = FreeFile
Open newFile For Output As #tf
Do Until EOF(ff)
Line Input #ff, Ln
If i = 0 Then
    TmpStr = Ln
Else
    TmpStr = TmpStr & "," & Ln
End If
Loop
Print #tf, TmpStr
Close #ff
Close #tf
Next i

End Sub
0
 
LVL 2

Accepted Solution

by:
rekhasri earned 50 total points
ID: 9822937
Hi,

ive just copied the file to a 2d array and written it back after transposing.

change the hardcodes acc to ur need

here is the code:
------------------------------------

Private Sub Form_Load()

Dim fso     As FileSystemObject
Dim f       As File
Dim ts      As TextStream
Dim sIp     As String
Dim txt()   As String
Dim tempArr() As String
Dim i       As Integer
Dim j       As Integer
Dim k       As Integer
Dim l       As Integer
Dim sOp     As String

Set fso = New FileSystemObject
Set f = fso.GetFile("F:\trials\New Folder\ip.csv")

Set ts = f.OpenAsTextStream(ForReading, TristateUseDefault)

i = 0
ReDim txt(10, i) As String
While Not ts.AtEndOfStream
    sIp = ts.ReadLine
    tempArr = Split(sIp, ",", , vbTextCompare)
    For j = LBound(tempArr) To UBound(tempArr)
        txt(j, i) = tempArr(j)
    Next j
    i = i + 1
    ReDim Preserve txt(10, i) As String
Wend

Set ts = f.OpenAsTextStream(ForWriting, TristateUseDefault)

For k = 0 To 9
    sOp = vbNullString
    For l = 0 To i - 1
        sOp = sOp & txt(k, l) & ","
    Next
    sOp = Mid$(sOp, 1, Len(sOp) - 1)
    ts.WriteLine (sOp)
Next

End Sub
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month7 days, 21 hours left to enroll

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question