+ Reply to Thread
Results 1 to 22 of 22

Drag & Drop csv file into Excel

  1. #1
    Registered User
    Join Date
    08-31-2009
    Location
    Mbabane, Zimbabwe
    MS-Off Ver
    Excel 2010
    Posts
    29

    Drag & Drop csv file into Excel

    I need to import numerous .csv files into a single Excel spreadsheet.

    Currently I open the .csv, press Alt & A to select all data and then copy / paste the date into the spreadsheet

    Is there a method to drag & drop .csv files into a spreadsheet?

    Thanks
    Last edited by TimTDP; 11-03-2011 at 02:28 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Drag & Drop csv file into Excel

    Perhaps a VBA help...

    'CSVs To Sheets
    I have a macro that may be "ready to use" for importing all CSV files in a folder into a single Excel sheet, each CSV filename will be listed on the sheet next to the data that it came from.
    CSVs to 1 Sheet



    How/Where to install the macro:

    1. Open up your workbook
    2. Get into VB Editor (Press Alt+F11)
    3. Insert a new module (Insert > Module)
    4. Copy and Paste in your code (given above)
    5. Edit the parts in red as needed for your workbook/CSVs
    6. Get out of VBA (Press Alt+Q)
    7. Save as a macro-enabled workbook

    The macro is installed and ready to use. Press Alt-F8 and select it from the macro list.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    08-31-2009
    Location
    Mbabane, Zimbabwe
    MS-Off Ver
    Excel 2010
    Posts
    29

    Re: Drag & Drop csv file into Excel

    Hi Jerry

    I have looked at your macro and it is great.

    However I want to place the new file to the right, rather than below.
    So the new file will always be placed in row 2, with the file name in row 1 (one cell only)
    Can you assist?
    Last edited by TimTDP; 11-02-2011 at 01:25 PM.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Drag & Drop csv file into Excel

    I've added a "Part 2" to the published page for your scenario. Try that version.

    'CSVs To One Sheet (Side By Side)
    I have a macro that may be "ready to use" for importing all CSV files in a folder into a single Excel sheet, each CSV filename will be listed above the data, the data imported into adjacent columns.
    CSVs to 1 Sheet - Part 2

  5. #5
    Registered User
    Join Date
    08-31-2009
    Location
    Mbabane, Zimbabwe
    MS-Off Ver
    Excel 2010
    Posts
    29

    Re: Drag & Drop csv file into Excel

    Works like a bomb.

    Thank you very much

    enjoy the steak!

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Drag & Drop csv file into Excel

    Thanks for the feedback!

    If that takes care of your need, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  7. #7
    Registered User
    Join Date
    08-31-2009
    Location
    Mbabane, Zimbabwe
    MS-Off Ver
    Excel 2010
    Posts
    29

    Re: Drag & Drop csv file into Excel

    I have messed something up!

    I have altered the code as follows (to change the csv slightly) as follows:

    Please Login or Register  to view this content.
    ActiveSheet.UsedRange.Copy wsMstr.Cells(1, NextCol) gives me the error:
    Application-defined or object-defined error.
    I get this if I hover the mouse over wsMstr.Cells(1, NextCol)

    What have I done wrong?

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Drag & Drop csv file into Excel

    You must religiously take OUT the selecting and activating you get from recorded code, merging all the rows down into fully addressed direct commands.

    Try this:
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    08-31-2009
    Location
    Mbabane, Zimbabwe
    MS-Off Ver
    Excel 2010
    Posts
    29

    Re: Drag & Drop csv file into Excel

    Thanks
    Same error on line:
    Range("A1:A" & KountRows).EntireRow.Copy wsMstr.Cells(1, NextCol)

  10. #10
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Drag & Drop csv file into Excel

    When you DEBUG and that line is highlighted, hover your mouse over KountRows and NextCol, what the values?

  11. #11
    Registered User
    Join Date
    08-31-2009
    Location
    Mbabane, Zimbabwe
    MS-Off Ver
    Excel 2010
    Posts
    29

    Re: Drag & Drop csv file into Excel

    KountRows = 5115
    NextCol = 0

  12. #12
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Drag & Drop csv file into Excel

    You can't paste data into column 0. Doesn't exist.

    The original full macro set the "NextCol" earlier the code than what you shared above. What did you change/omit? That variable must be set prior to entering the the DO LOOP section. Let me see your full edited version.

  13. #13
    Registered User
    Join Date
    08-31-2009
    Location
    Mbabane, Zimbabwe
    MS-Off Ver
    Excel 2010
    Posts
    29

    Re: Drag & Drop csv file into Excel

    Thanks. Don't know why but I set NextCol = 0

    However, Excel now tells me I can't paste because the copy & paste areas are not the same!
    Run time error 1004

  14. #14
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Drag & Drop csv file into Excel

    Quote Originally Posted by JBeaucaire View Post
    Let me see your full edited version.
    Hmmm..... still waiting.

  15. #15
    Registered User
    Join Date
    08-31-2009
    Location
    Mbabane, Zimbabwe
    MS-Off Ver
    Excel 2010
    Posts
    29

    Re: Drag & Drop csv file into Excel

    Please Login or Register  to view this content.
    Last edited by TimTDP; 11-05-2011 at 09:45 AM.

  16. #16
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Drag & Drop csv file into Excel

    Try:
    Please Login or Register  to view this content.

  17. #17
    Registered User
    Join Date
    08-31-2009
    Location
    Mbabane, Zimbabwe
    MS-Off Ver
    Excel 2010
    Posts
    29

    Re: Drag & Drop csv file into Excel

    unfortunately not
    Same error

  18. #18
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Drag & Drop csv file into Excel

    If KountRows = 0 then this will never work. Why is your data in the opened workbook showing nothing in column A?

  19. #19
    Registered User
    Join Date
    08-31-2009
    Location
    Mbabane, Zimbabwe
    MS-Off Ver
    Excel 2010
    Posts
    29

    Re: Drag & Drop csv file into Excel

    I have created an entry in A1, but still get the same error

    I have attached my files. Could you have a look at them?
    The files with numeric names are the data files I want to import.
    The first import work, and this is the result I want for all imported files.

    Many thanks
    Attached Files Attached Files

  20. #20
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Drag & Drop csv file into Excel

    You had messed up the copy/paste of the "else" part of the first section. Also, I changed that copy/paste command to only copy the number of columns needed instead of trying to copy the entire row, that seems to have resolved it.
    Please Login or Register  to view this content.

  21. #21
    Registered User
    Join Date
    08-31-2009
    Location
    Mbabane, Zimbabwe
    MS-Off Ver
    Excel 2010
    Posts
    29

    Re: Drag & Drop csv file into Excel

    Thank you very much

  22. #22
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Drag & Drop csv file into Excel

    If that takes care of your need, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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