Here's my stock macro for this task, edited for your task.
Option Explicit
Sub Consolidate()
'Open all Excel files in a specific folder and merge data into master sheet
'Moves imported files into another folder
'JBeaucaire (9/15/2009) (2007 compatible) EDITED: 3/13/2010
Dim fName As String, fPath As String, fPathDone As String, OldDir As String
Dim LR As Long, NR As Long
Dim wbData As Workbook, wbNew As Workbook, ws As Worksheet
'Setup
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.DisplayAlerts = False
Set wbNew = ThisWorkbook
wbNew.Activate
'Path and filename
OldDir = CurDir 'memorizes the users current working path
fPath = "C:\2010\" 'remember final \ in this string
fPathDone = fPath & "Completed\" 'remember final \ in this string
On Error Resume Next 'creates the completed folder if missing
MkDir fPathDone
On Error GoTo 0
ChDir fPath
fName = Dir("*.xls")
'Import a sheet from found file
Do While Len(fName) > 0
If fName <> wbNew.Name Then
'Next row
NR = wbNew.Sheets("RawData").Range("A" & Rows.Count).End(xlUp).Row + 1
'Open file
Set wbData = Workbooks.Open(fName)
'Copy named range
Range("NamedRange").Parent.Activate
Range("NamedRange").Copy wbNew.Sheets("RawData").Range("A" & NR)
'Rename activesheet and copy to master file
ActiveSheet.Name = ActiveSheet.Range("A1") 'cell with text for sheet name
ActiveSheet.Copy After:=wbNew.Sheets(wbNew.Sheets.Count)
'close file without saving any changes to it
wbData.Close False
'move file to completed folder
Name fPath & fName As fPathDone & fName
End If
'ready next filename
fName = Dir
Loop
'Cleanup
wbNew.Sheets("RawData").Columns.AutoFit
wbNew.Sheets("RawData").Rows.AutoFit
Application.DisplayAlerts = True
Application.EnableEvents = True
Application.ScreenUpdating = True
'restores original working path
ChDir OldDir
End Sub
Bookmarks