Import n .csv data

G

Guest

I've been trying to work out my problem from bits of other peoples answers
without success. I have n number of .csv files in a folder. I need to import
into an Excel file a specific column of data from each file, then delete the
file once it's complete. The column range in the .csv file is always the same
(C2:C54). I'm very new to VBA & I am struggling. Can anyone help?
 
T

Tom Ogilvy

Dim sh as Workshet
Dim sName as String
Dim rng as Range
Dim bk as Workbook
set sh = Activesheet
sName = Dir("C:\Myfolder\*.csv")
do while sName <> ""
set bk = Workbooks.Open( "C:\MyFolder\" & sName)
set rng = bk.Worksheets(1).Range("C2:C54")
rng.copy destination:=sh.Cells(1,256).End(xltoLeft)(1,2)
bk.close SaveChanges:=False
sName = Dir()
Loop
Kill "C:\MyFolder\*.csv"
 
G

Guest

Tom, thanks a bundle. I realise now I've been looking for the hard way to do
it all weekend! Many thanks again, it works a treat
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top