Automate tasks to access data within excel files - excel

I am between beginner and intermediate user of excel with no coding background. Not sure if I need to use power query or not for this. If not, any VBA code to accomplish the same would be great.
I want to automate the consolidation of data and processing it for 10 production lines.
Each production line has its own folder on the drive.
Within each line's folder, there is a monthly folder example - March, April etc.
Within each Monthly folder there is a day folder - May 1, May 2 , May 3, etc.
Within each day there are 3 excel files - Shift 1, Shift 2 and Shift 3.
Data for each shift for 10 different lines is collected and manually entered into its specific shift excel file by production operators.
There is a master file located elsewhere on the drive which processes data from these lines but currently it has to be manually transferred to the master file - which is a pain and super time consuming.
The master file contains 2 worksheets for each production line. I would like to copy and paste specific range of cells (H9:R24) from the shift production line files into specific worksheets within the master file specifically made for those production lines.
The column before the cell ranges where I would like to paste the data (in the master file) contains dates and hence I am hoping that the code/query will help me paste via matching the date from within the shift excel file.
Each shift excel file is exactly the same in terms of naming of columns, formatting, formulas etc.
Once pasted into the specific worksheet within the master file, cells in another worksheet (within the master file) use these numbers to process these via formulas and more numbers are generated such as waste % etc. which will be automatically plotted on different graphs.
I would like to super automate this process with a click of the button in the master file to access the data within those files, copy and paste into specific cells in specific worksheets within the master file and process data according to specified formula (already within the cell) to ultimately give processed numbers and graphs for each line for the previous day.
This needs to be repeated for 30 files - 3 files each for each day for 10 lines - every single day first thing in the morning.
Not sure if I need to use power query or not for this. If not, any VBA code to accomplish the same would be great.
Requesting you kindest help.
Thank you !

Power Query is the best tool for this task. You should not need any VBA.
Start with Get Data / From Folder and point it at your root folder for all production lines. It will browse all the subfolders and give you a list of files, with the path for each, as a table.
As long as the individual file content is consistent, you can then hit Combine to generate a Function Query that will repeat for each file. You'll need to build your transformation logic in that query.
You can build queries by "Reference" to this main query, e.g. transforming the data for a specific chart requirement.
The "click of a button" will be on Excel's standard Refresh button - that will re-run all the queries and refresh their output tables. That can be automated with a one-line VBA macro or using the Power Update add-on.

Related

Using a Macro to update daily statements in a master file from a saved location

I am looking to add a macro button into my summary sheet of my master file. The main tab will have a summary of the values, then there will be 5 other tabs named initial,1,2,3,4.
The tabs initail - 4 are just financial statements that have been pasted into the file.
I basically want to have a button on the cover that will update the data in the initial - 4 sheets with the new data for the current day. The current day files will be saved down in a separate daily folder each day in the same path. The new files will be consistently laid out and formatted the same. So I would simply need the macro to pull the files from todays date file path and paste the files into the corresponding tabs of the spreadsheet. The files can be saved down under the corresponding names of the tabs.
I have tried looking for help online but can’t see anything that would apply. I feel it is fairly simple however I have no experience working with VBA code only recording macros. Any help would be massively appreciated.
Thanks in advance

How to append one excel file as a sheet onto another excel file in alteryx

so I have about 90 different excel files that are customer reports. I have one generic excel file that's a summary page that I need to insert as a sheet into all of those other excel files. Does anyone have a way to automate this process - I'm generating the sheets through alteryx but open to solutions outside of that platform or maybe there's a simple way to do it through Excel that I'm missing.
Right now, the only option is to open each report and copy over the summary sheet and insert it that way. To do it for 90 sheets would take me over an hour so trying to shorten the time.

Dynamic Workbook Name changes and cell references - Is it possible?

my question is a pre-code question, as I would like to verify if and which is the best option to go about this - either formula, VBA or not possible.
I have a main workbook with an array of codes inside cells in sheet 1 - all in the format HXXX-XXX-XXX where X is numbers ranging from 0-9. Each code has an associated revision number as shown in the attached picture.
The workbook itself is named in the format: 'HXXX-XXX-XXX-YY Example Title' where YY can be any number starting from 0 to infinity (in theory). Only YY is subject to updates in the title. If changes are made in this workbook, then a new version is saved, with the YY changing in the title to the next consecutive number - Nothing else changes.
From this main workbook there are a large number of other workbooks (around 50) which share the same codes and revisions. My goal is to link all these workbooks up so that I only have to update a core main workbook and the rest of the codes (HXXX-XXX-XXX) revisions in all the other linked workbooks update accordingly.
The problem is that the other linked workbooks have a dynamic name in the format: 'HXXX-XXX-XXX-YY Example Title 2' where YY can be any number starting from 0 to infinity. YY gets updated to the next consecutive number if a change is made inside the document and this document is then saved as a separate document using Save As. NOTE: not all workbooks will get updated at the same time, as it all depends on which codes and therefore revisions are changing.
My question is firstly, is this possible with current excel functions to update links with ever-changing workbook links, which are saved as different files each time in the same folder?
Secondly, I have read about the INDIRECT function, but it is limited only to having the required workbooks opened at the same time as the updates to the main workbook, hence I am unsure that Formulas will work (I will be linking 50 workbooks to the main workbook) - From this I am gauging that VBA may be the best option, but I would like to double check this is possible before I begin attempting the code.
Of course the use of Formulas in the sheets would be much better, but because the file names are dynamic, and since the updated workbooks are saved as different files each time changes are made to it, I don't believe this is possible.
If I understand your problem correctly you need to differentiate between 3 things.
Using only Excel Formulas.
The problem with this is that formulas crossing workbooks have the big disadvantage, that you need to have the source-workbook open, otherwise manny formulas will not work correctly or update. You also have the disadvantage that saving the file needs still to be done automatically. The advantage is that you do not need VBA macros.
Using Power Query
With Power Query youmight be able to solve the problems with the dynamic names.You can even read a whole folder of files, combine them and do transformations without the need to open the files manually. But you still need to save new files manually and the files will only update once they are opened.
Using VBA
You can prettymuch do everything you asked in your problem description but VBA has its own disadvantages. Firstly the file-format ".xlsm" is not allowed by the IT department everywhere. Also to work, every user using the files needs to activate macros, otherwise the macros won't get executed. Therefore I think a VBA solution is better fitted if you only have a small circle of users or if you can execute the macros on your own (e.g. if the main workbook was updated, you need to execute a macro which opens, modifies and saves all affected files). After that you colleagues do not need VBA themself.
Possible solution:
To avoid VBA you could try to create a Power Query in each "other workbook". The query will read all filenames in the folder where the main workbook is located. Now you sort and filter for the workbook with the newest/highest ID/Titel automatically and load the result as an seperate Excel sheet (all that is possible with power query and without VBA).
Now you can use the "indirect" formula to use the ID/Titel to link to the newest main workbook. As mentioned above this will require that the main workbook is opened. Otherwise the indirect formula will not update the values. If that is out of the question, you probably need to go with VBA.

Data Copy using Excel-VBA

I am having a folder of 10 excel-based CSV files. Is there any method to copy the data from all these files into 1 excel
Not good with VBA, so thought to ask you guys
On a first sight, I would go for the following approach (coming up with the codes is up to you, Google is your friend):
Get a list of all file names within that directory
Iterate over every item from the above list and open the file with Workbooks.Open(...)
Copy the whole content and paste it to the additional Excel you want to manage to hold the data of all files
Repeat the steps for each file
Remember to save the last row after every paste s.t. you can continue with amending the data into the addtional Excel instead of replacing the content.

Copy a column of formulas to a closed workbook in Excel

I have a lot of data into Excel files.
There are about 174 files. Each is named Book2.xslx through Book174.xlsx
I have a master document where I have a column of formulas that I would like to paste (or insert) into each of these spreadsheets without having to actually open each one individually.
Does someone know any code I can use to do this?
As an example, I would say I would want to copy the range P:P - the whole of column P - and insert it or paste it into Column P in the closed workbooks.
Can this be done? If it works , and I want to insert different ranges and cells every time I wanted something different inserted or pasted? Or is there a macro for example, that I could run , that would copy what I've selected to the same place in every unopened spreadsheet named Book*.xlsx?
You cannot do this on existing files without opening them (whether in Excel, or using FSO, as the Object Model won't be available to apply to those files
having said that, it is possible to automate the modifications using VBA.
If you would post your code, we can help you improve it or resolve any issues with bugs or performance

Resources