Hi,
Good to hear it is working, and glad I could help.
Regarding the code...
This sets the base location and stores it in the Folder variable.
sFile is another variable that stores the first file in the sFolder location
Dir() is a VB function that collects files in a folder (in this case specifically CSV files based on the *.csv extention)
ScreenUpdating switches off the screen refresh...speeding up the macro and preventing screen movement
The Do loop makes use of the VB function InStr() to inspect the file name loaded into the sFile variable by Dir.
The syntax is: InStr(Phrase to search, Term to search for within the Phrase)
The InStr(...)>1 (ideally could be >0; I changed it below, though it will not make a difference in your macro) means that if it finds the term in the phrase, the returning value of InStr = the start position of the term. Basically, if it finds the term in the phrase it will be >0 (eg: =InStr("Hello big world", "big") will equal 7)
It determines if the filename has any of three key words (hour, period and month). It needs this to know which sheet it is processing and to which destination sheet it needs to paste the data. Having said this...it is important that these terms are present in the file name and the sheet names.
Once the
Here the code opens the referenced workbook from the file path
Stores the file name of the opened workbook
Copies the current region range from the source to cell A1 in the destination sheet
Closes the source file
CurrentRegion is a special selection property that extends a selected cell outwards until it encompasses its entire block.
Lastly, Dir() is called again to populate the sFile variable with the next File name in the folder.
The Do...Loop will execute until the last file in the folder (that is CSV in this case...based on the filter *.csv)
This finished the macro by switching screen refresh mode back on.
Hope that explains a bit more about the code...
Bookmarks