Add a column with file name while importing .csv file in vba

  • Hello
    Over the years I have always found what I needed eventually by searching, I have some code I have been using and it works spectaculary, and after hours i cant seem to get it right


    But I would Like to take it one step farther, I need it to take the file name and add a column


    IE it currently goes through each file in a folder and pulls 2 columns from it and pastes those into excel moving to right as it goes througg say 500 files
    it currently puts the file name above the last column which has worked great until i want to manipulate the date easier.



    [ATTACH=CONFIG]67053[/ATTACH]


    So if possible I was wondering if anyone knew how to change my code so that it will have the "name of text file" then the 2 columns, then repeat like it does now


    Actually another thing that would be great is, instead of being across like it is, add the name of the text file and just have 3 rows going downward instead of Left to right like now, so i can make a pivot table, not sure which way i would like best but either is great


    Anyway i hope i have explained it enough


    here is my code


  • Re: Add a column with file name while importing .csv file in vba


    hello,
    Maybe just write straight to the worksheet

  • Re: Add a column with file name while importing .csv file in vba


    See if this is how you wanted (not tested)


    Originally
    http://www.ozgrid.com/forum/showthread.php?t=80643

  • Re: Add a column with file name while importing .csv file in vba


    hello,
    Maybe just write straight to the worksheet

    Hi, When running this code on my Scenario, I am getting "Sub or Function not defined" for the 'Cells' function (line 14). I'm assuming I need to specify the file. (I tried 'fn.Cells', 'x.Cells',) but still no joy. Quite new to VBA, can you help? Thank you!

  • Please start your own thread, rather than hijacking someone else's.

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!