+ Reply to Thread
Results 1 to 9 of 9

give column name to a csv file

  1. #1
    Registered User
    Join Date
    04-11-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    46

    give column name to a csv file

    I was just wondering if this can be achieved in excel (or rather csv)

    I have around 500 csv files, each with four columns of data. However, the first column does not have a heading. Is there any way I can give the column name to the first column in each of 500 csv files? Here is one of the csv files:

    name1 name2 name3
    177 4.77 4.15 29.28
    178 10.45 6.24 50.36
    182 57.86 16.9 169.11
    183 26.46 20.1 18.93
    184 1.48 20.29 0.95
    185 0.84 20.45 0.79
    203 1.49 3.44 8.86
    204 0.06 3.41 -0.87
    205 0.02 3.37 -1.17
    206 0.91 3.51 4.15
    207 11.35 2.77 -21.08
    208 5.23 3.51 26.71
    209 0.02 3.51 0
    210 0 3.5 -0.28
    211 0.06 3.33 -4.86
    212 29.25 6.91 107.51

  2. #2
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: give column name to a csv file

    So, you want to loop over all the files, and just add a line with the 4 headers at the very top, then save the resulting file?

    Can you localize all the files to a single directory?
    Remember, saying thanks only takes a second or two. Click the star icon(*) below the post you liked, to give some Rep if you think an answer deserves it.

    Please,mark your thread [SOLVED] if you received your answer.

  3. #3
    Registered User
    Join Date
    04-11-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    46

    Re: give column name to a csv file

    Yes that pretty much I want to do. If by localise you meant having all the files in a single folder, then yes I have all the files in a single folder

  4. #4
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: give column name to a csv file

    k, i can help i think. I have a similar loop in my personal macros. let me see if i can alter it for you

  5. #5
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: give column name to a csv file

    Ok, check out the attached file. You'll need to type in the full path to the folder holding the CSV's (note, it will actually look in any subfolders within that folder too), AND you will need to enter another path for the output.

    Basically, the routine will alter each file and save it to a new file (so you will have the old files and the altered copy sitting in different folders)

    Here is the code - the attachment should be good to go. Let me know how it goes please

    Please Login or Register  to view this content.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    04-11-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    46

    Re: give column name to a csv file

    Thanks man!! this was really good. However, there is just one slight problem..it is doing the right thing but instead of overwrting the current column names, it is adding a new one row with the four column n

    previous file:

    name1 name2 name3
    1 2 3 4

    new file:

    H1 H2 H3 H4
    name1 name2 name3
    1 2 3 4

    It is not overwriting the old column names in the old files but adding the new column names just above the old names. Is there any way I can produce this file:
    H1 H2 H3 H4
    1 2 3 4

    I see that you have spent lot of time and energy on this and I am really thankful to you for the help you are putting in.
    Last edited by kuntalnr; 07-08-2014 at 12:46 PM.

  7. #7
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: give column name to a csv file

    ohhh.... i thought the first row you mentioned was an example of what you were after. I see now.

    I think it's a simple matter but I'll have to tinker with it later. I'll post what i find.

  8. #8
    Registered User
    Join Date
    04-11-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    46

    Re: give column name to a csv file

    Hey thanks a lot. But I managed to do it in some other software. But I really appreciate your time and help. Cheers!

  9. #9
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: give column name to a csv file

    Man, it was really easy - just had to add a "skipline" to ignore that line

    I posted it anyway because it might help someone else. Please mark your thread solved.



    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 2
    Last Post: 04-16-2014, 05:13 PM
  2. Replies: 9
    Last Post: 11-19-2013, 06:48 AM
  3. Copy hyperlink file to another location and give it a new file name
    By karole in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-26-2012, 03:50 PM
  4. how do i give password to open for Excel File?
    By SWATI GAMBHIR in forum Excel General
    Replies: 1
    Last Post: 02-24-2005, 05:06 AM
  5. calculate which cells in column A will give me the total of column
    By Ken in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-06-2005, 03:06 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1