+ Reply to Thread
Results 1 to 2 of 2

Run macro on many csv files and append only one row into master excel file

Hybrid View

  1. #1
    Registered User
    Join Date
    08-29-2012
    Location
    Wherever
    MS-Off Ver
    Excel 2003
    Posts
    1

    Run macro on many csv files and append only one row into master excel file

    Hello All,
    Newbie here. I have more than 200 csv files in a folder with names like xxxxx_1.csv until xxxxx_225.csv. Almost all csv files contain 65500 rows and 20 columns. There are several macros that run on each csv file. The information I need after the macro processing is always stored in one row from W3 to AF3 (10 columns wide) of each csv file. I used to have only 3 or 4 csv files, so I ran the macros and copied only the output results from each csv file and appended to an existing master excel file.
    Now with more than 200 csv files (and more expected), this is very inefficient. Is there a way to automate the process of running the macros on each csv file, copying only what is required and appending it to an existing excel file?
    (I don't know if it's important, but the output of each csv file need not be saved in the csv file itself if the process is cumbersome. I'd anyway have it in the master output excel file).

    Thanks a million!

  2. #2
    Registered User
    Join Date
    08-27-2012
    Location
    Saldanha, South Africa
    MS-Off Ver
    Excel 2010
    Posts
    59

    Re: Run macro on many csv files and append only one row into master excel file

    Dim myWB as workbook
    
    myWB = activeworkbook 'this the master workbook where from you run this macro and collect the data
    
    
    myFolder = "C:\myfiles\"
    myFile = Dir(myFolder & "*.csv")
    
    Do While myFile <> ""
    
    	Workbooks.Open Filename:=myFolder & myFile
    
    	call myMacro 'call the macros here 
    	
    	'the following copy the cells, determine the last cell used in your master file and paste
    	Range("W3:AF3").Select
    	Selection.Copy		
    	myWB.Activate
    	Range("a1048576").Select 
    	Selection.End(xlUp).Select
    	ActiveSheet.Paste
    
    	workbooks(myFile).activate
    	Application.CutCopyMode = False
    	ActiveWorkbook.Saved = True
    	ActiveWorkbook.Close
    
        myFile = Dir()
        
    Loop

+ 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