You've probably seen the SQL needs adjusting to match the sheet name. This will need to be automated.
Whether this is worth doing or not depends on how big your task is; if it's on a daily basis it may be worth doing. Only once every 6 months? Use
Mike7952's solution. 50 files at once? We can probably process 50 files in one go in less than a minute by tweaking my offering.
JL : Thank you for below briefly explanation!!
Actually, the files are related for the order creations. The Original Raw Data file got the column from A to EH with the different color in the Header cell so that it was modified for posting the question.
So… lots of questions:
Is there always only one sheet per .xlsx data file?
JL : Yes. There is always 1 sheet per .xlsx data file.
Is the table always at cell A1?
JL : The Header of those files is always at cell A1 and the Header is highlighted with different colors. In general, there are no value in 1st & 2nd column and only has the Header.
Does the data come to you in Excel format? (If it comes to you as a .csv file, your computer may be opening it by default as an Excel file (and identifying it as such) but it isn't really and it could be interrogated directly.)
Does it comes in any other format? (It may be easier to get the data directly.
JL : Those files always come in Excel format.
Perhaps attach a sample or two of the real data files here (if sensitive info is in them, ask me for a personal email address via Private Messaging here so that you can send them privately.
JL : I'm sorry that I don't have the real data files right now.
BTW, the adjustment needed for your 459GEF sheet would probably be:
.CommandText = "SELECT DISTINCT `Lot #`, CC, Path, Plant, Type FROM `459GEF$`"
replacing the existing similar line.
You need of course to select the file with that sheet name in (
2017 ACC.xlsx?) when the macro runs.
Note that it's considerably shorter than my original (recorded) version of that line.