Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Junior Member
 
Posts: 1
Default Macro to Read Multiple CSV files into Excel

Hi,

I've written the macro below to read in and append several csv files together in excel. It works but can anyone tell me how I alter it to read only the header row from the first file?

Thanks
Kirstin

Sub List_All_The_Files_Within_Path()
Dim File_Path As String
Dim cell_to_paste_next_dataset As Range
Dim active_workbook, dataset_workbook As Workbook
Dim active_sheet As Worksheet
Dim file_count As Integer

Application.DisplayAlerts = False

'SPECIFY LOCATION of CSV FILES
File_Path = "S:\Data"

Set cell_to_paste_next_dataset = Cells(1, 1)
Set active_workbook = ActiveWorkbook
Set active_sheet = ActiveSheet
With Application.FileSearch
.NewSearch
.LookIn = File_Path
.Filename = "*.csv" 'CHANGE FILE EXTENSION TO OTHER EXCEL BASED EXTENSION IF YOU WANT
.SearchSubFolders = False
.Execute
For file_count = 1 To .FoundFiles.Count
If File_Path & "\" & active_workbook.Name < .FoundFiles(file_count) Then
Workbooks.Open Filename:=.FoundFiles(file_count)
Set dataset_workbook = ActiveWorkbook
Range(ActiveCell.SpecialCells(xlLastCell), Cells(2)).Copy
active_sheet.Activate
Cells(ActiveCell.SpecialCells(xlLastCell).Row, 1).Select
ActiveSheet.Paste
dataset_workbook.Close
End If
Next file_count
End With
End Sub
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to access multiple Excel files [email protected] Excel Discussion (Misc queries) 4 March 7th 07 04:50 PM
Macro: Filter Multiple header then extract to Multiple Files [email protected] Excel Discussion (Misc queries) 9 December 8th 06 10:44 PM
Run multiple excel files off of one macro. ahsya Excel Discussion (Misc queries) 5 October 4th 06 03:01 PM
Run multiple excel files off of one macro. ahsya Excel Worksheet Functions 1 October 3rd 06 11:43 PM
Excel read-only files srcmeador New Users to Excel 1 March 16th 06 03:39 PM


All times are GMT +1. The time now is 09:14 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"