How to transpose multi CSV files in a folder using VBA into 1 excel file

amir988

New Member
Joined
Nov 20, 2015
Messages
13
I have a folder in C:\CSV\ where more then 6000 csv files are available and the more important thing is, every csv file has only one colum but many rows. Now i want to transpose all csv files and make it one file in excel where transposed data shown. there is no name of column and rows. Any one plz guide.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Now i want to transpose all csv files and make it one file in excel where transposed data shown
if i read your post correctly, you want to do the folling on each file in the directly???
Code:
[QUOTE="arthurbr, post: 5404960, member: 71680"]
Try Merge all CSV or TXT files in a folder in one worksheet
[/QUOTE]that's not bad.  as an alternative, which is what I was just checking on, I found that this:[code]
Public Function txtstreamreadall_h()
Dim fs As Object, s As String, a As Object
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set a = fs.openTextFile("C:\Users\Owner\Desktop\1.csv", 1)
    s = a.readall
    txtstreamreadall_h = s
    a.Close
End Function
returns the entire content of a csv file with line breaks included. whereby this:
Code:
Public Function finput_h()
Dim f As String, text As String, textline As String
f = "C:\Users\Owner\Desktop\1.csv"
    Open f For Input As #1
        Do Until EOF(1)
            Line Input #1, textline
            text = text & textline
        Loop
    finput_h = text
    Close #1
End Function
also does the same thing but returns the entire file's content *without* the line breaks in it. another resource to use, which is pretty well known, for looping through files in a directory is allen browne's famous page: Microsoft Access tips: List files recursively
 
Upvote 0
if i read your post correctly, you want to do the folling on each file in the directly???
Code:
[QUOTE="arthurbr, post: 5404960, member: 71680"]
Try Merge all CSV or TXT files in a folder in one worksheet
[/QUOTE]that's not bad.  as an alternative, which is what I was just checking on, I found that this:[code]
Public Function txtstreamreadall_h()
Dim fs As Object, s As String, a As Object
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set a = fs.openTextFile("C:\Users\Owner\Desktop\1.csv", 1)
    s = a.readall
    txtstreamreadall_h = s
    a.Close
End Function
returns the entire content of a csv file with line breaks included. whereby this:
Code:
Public Function finput_h()
Dim f As String, text As String, textline As String
f = "C:\Users\Owner\Desktop\1.csv"
    Open f For Input As #1
        Do Until EOF(1)
            Line Input #1, textline
            text = text & textline
        Loop
    finput_h = text
    Close #1
End Function
also does the same thing but returns the entire file's content *without* the line breaks in it. another resource to use, which is pretty well known, for looping through files in a directory is allen browne's famous page: Microsoft Access tips: List files recursively
Merging is not a problem overall, i can merge even a more easy using CMD command, using copy *.csv combined.csv problem is in transposing the data, how do i transpose the csv files in a folder. where files doest not have any name of columns and rows. and csv files contain only 1 column but multiple rows.
 
Upvote 0
01.JPG02.JPG03.JPG Check out here i have data shown in img 1 and 2. and i want like img 3. that it.
 
Last edited by a moderator:
Upvote 0
hey bud, I think I've got it. change this to suit your needs:
Code:
Public Function txtstreamreadall_h()
Dim fs As Object, s As String, a As Object, counter As Long, counterArray As Long, arr() As String, cRow As Long, cOffset As Long
cRow = 1
    For counter = 1 To 4
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set a = fs.openTextFile("path where files are" & CStr(counter) & ".csv", 1)
        s = a.readall

        a.Close
            arr() = Split(s, vbCrLf)
                cOffset = 0
                For counterArray = LBound(arr) To UBound(arr)
                    Range("a" & CStr(cRow)).Offset(0, cOffset) = arr(counterArray)
                    cOffset = cOffset + 1
                Next counterArray
        cRow = cRow + 1
    Next counter
End Function
 
Upvote 0
hey bud, I think I've got it. change this to suit your needs:
Code:
Public Function txtstreamreadall_h()
Dim fs As Object, s As String, a As Object, counter As Long, counterArray As Long, arr() As String, cRow As Long, cOffset As Long
cRow = 1
    For counter = 1 To 4
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set a = fs.openTextFile("path where files are" & CStr(counter) & ".csv", 1)
        s = a.readall

        a.Close
            arr() = Split(s, vbCrLf)
                cOffset = 0
                For counterArray = LBound(arr) To UBound(arr)
                    Range("a" & CStr(cRow)).Offset(0, cOffset) = arr(counterArray)
                    cOffset = cOffset + 1
                Next counterArray
        cRow = cRow + 1
    Next counter
End Function
thats work like charm. thank u
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top