Hi,
I am trying to copy several hundred sheets of data in separate workbooks into one single workbook and all on one sheet.
I have the code which will work if I define the specific name of the sheet to pull the information from in this case my sheets are names "Driving_001"... right through to 700 sometime more sometimes less. The dynamic part of my sheets is 001...002...003 and so on
Is there a way in this code to allow it to recognise the sheets as they are opened? This is the part I want to be dynamic:
Sheets("Driving_001").Range("A1:A5000").Copy
Thanks in advance
Izzy
I am trying to copy several hundred sheets of data in separate workbooks into one single workbook and all on one sheet.
I have the code which will work if I define the specific name of the sheet to pull the information from in this case my sheets are names "Driving_001"... right through to 700 sometime more sometimes less. The dynamic part of my sheets is 001...002...003 and so on
Is there a way in this code to allow it to recognise the sheets as they are opened? This is the part I want to be dynamic:
Sheets("Driving_001").Range("A1:A5000").Copy
Code:
Sub Collaborate()
Set ws = Worksheets("Variables")
FileType = "*.csv*" 'The file type to search for
FilePath = ws.Range("A3") 'The folder to search
OutputCol = 1 'The first row of the active sheet to start writing to
ThisWorkbook.ActiveSheet.Range(Cells(3, OutputCol), Cells(3, OutputCol)) = FilePath & FileType
OutputCol = OutputCol + 1
Curr_File = Dir(FilePath & FileType)
Do Until Curr_File = ""
Set FldrWkbk = Workbooks.Open(FilePath & Curr_File, False, True) 'Open new data file
Sheets("Driving_").Range("A1:A5000").Copy 'Copy data from specific Range
'Move back to Master file
Workbooks("TMS_V0_2.xlsm").Activate
Sheets(1).Cells(4, OutputCol).Select
ActiveSheet.Paste
OutputCol = OutputCol + 1
FldrWkbk.Close SaveChanges:=False 'Close the data file
Curr_File = Dir 'Select Next File
Loop
Set FldrWkbk = Nothing
End Sub
Thanks in advance
Izzy