Import *.csv formatted multiple files from folder in to excel

Kishan

Well-known Member
Joined
Mar 15, 2011
Messages
1,648
Office Version
  1. 2010
Platform
  1. Windows
Using Excel 2000</SPAN></SPAN>

Hi,</SPAN></SPAN>

I have created one folder on desktop and named "csvfiles" when I receive a new file I just add into this folder (in the same folder I have put one excel workbook named "csvfilestoexcel" </SPAN></SPAN>

I want I code when I open "csvfilestoexcel" and run the macro it list all the files are in to the folder "csvfilestoexcel" in the sheet1 into the column A and then all "csvfiles" are listed in the sheet1 import them one by one in the sheet "Imported"</SPAN></SPAN>

Is it possible?</SPAN></SPAN>

This is code I have recorded and imported 2 columns data from 2 files a1 & a2 and paste them transpose in to sheet "Imported" need a code which can do import all files automatically </SPAN></SPAN>
Code:
Sub Import_Csvfiles()
    Sheets("Imported").Select
    ChDir "D:\Desktop\csvfiles"
    Workbooks.Open Filename:="D:\Desktop\csvfiles\a1.csv"
    Range("C1:C14").Select
    Selection.Copy
    Windows("csvfilestoexcel.xls").Activate
    Range("D10").Select
    Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=True
    Range("S10").Select
    Windows("a1.csv").Activate
    Range("D1:D14").Select
    Application.CutCopyMode = False
    Selection.Copy
    Windows("csvfilestoexcel.xls").Activate
    Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=True
    Range("D11").Select
    Windows("a1.csv").Activate
    ActiveWindow.Close
    
    
    Workbooks.Open Filename:="D:\Desktop\csvfiles\a2.csv"
    Range("C1:C14").Select
    Selection.Copy
    Windows("csvfilestoexcel.xls").Activate
    Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=True
    Range("S11").Select
    Windows("a2.csv").Activate
    Range("D1:D14").Select
    Application.CutCopyMode = False
    Selection.Copy
    Windows("csvfilestoexcel.xls").Activate
    Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=True
    Range("D9").Select
    Windows("a2.csv").Activate
    ActiveWindow.Close
    ActiveWorkbook.Save

End Sub
</SPAN></SPAN>

Example of imported files</SPAN></SPAN>


Book1
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAH
1
2
3
4
5
6
7
8
9
1046,346,89056,626,630,955,331,837,14359,643,857,565,428,928,47,4425,525,830,227,132,932,331,526,529,727,824,1
1132,54,4630,755,210,438,259,128,740,458,335,160,153,530,62910,829,224,417,729,225,532,933,22731,327,42732,2
12
13
14
Imported


Thank you in advance</SPAN></SPAN>

Regards,</SPAN>
Kishan</SPAN>
 
Vba imports them as they are in the folder, for that you have the columns, to sort by date, check that it really is a date and not a text
DanteAmor, solved! sorting by date it worked like a charm </SPAN></SPAN>

I appreciate your help very much

Thank you
</SPAN></SPAN>

Kind Regards,
</SPAN></SPAN>
Kishan :)
</SPAN></SPAN>
 
Upvote 0

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Forum statistics

Threads
1,223,903
Messages
6,175,279
Members
452,630
Latest member
OdubiYouth

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