I have to move a large amount of data from workbook A to workbook B in excel - workbook A has a different organizational structure than workbook B, and I want to automate A to transfer to B and organize itself into B's structure. I'm just getting acquainted with VBA, but before potentially wasting a lot of time - is this something VBA can do?
Definitely, as long as you have a reliable set of steps for translating the information from one format to another. If that's the case, then they can be codified and implemented in VBA.
If you're just getting acquainted with VBA, do some cost-benefit analysis. Sometimes it's faster to do it by hand. That being said, it will be very satisfying if you can get it to work. Nothing like going on a coffee break while your work does itself.
Related
tl;dr: Is there a way to have multiple (10+) excel Macro workbooks run the same project from a single location so that if I need to fix a bug, I don't need to fix it in every single workbook?
Long version:
My company uses excel workbooks for engineering charts. Any changes are formatted as bold and highlighted gray. We then have a revision "table" at the bottom (I say "table" because it's just some merged cells - there doesn't seem to be a way to make a separate table that doesn't follow the column sizing for the rest of the workbook, but that's a question for another day).
When we do a new revision, we have to first clear any formatting from the previous revision, make our changes (and format them), then insert a row to the revision "table", then unformat the previous revision entry and reformat our new revision entry. Then, we export the workbook as a PDF which we name according to our print naming format. However, it is easy to make mistakes when doing this because the file name must be manually entered according to the format.
To make this process less tedious/error-prone, I wrote a VB macro program to automate the above steps, among other things. It works great, and will be implemented on our charts company wide.
However, I can only do so much testing on my own - there are bound to be things I missed or can do more efficiently (I'm an engineer, not a professional programmer). And we have dozens of engineering chart spreadsheets. If we implement this and then I discover I need to fix a bug or make an improvement to part of the program, I don't want to have to fix it in every single workbook - that would take way too long and be too easy to miss a workbook!
Any advice would be appreciated.
I'm working with a rather large Excel document (~9MB) in size which has over 60 sheets and each containing many CUBEVALUE formulas in it.
This document takes over 2 minutes to open (not counting refreshing of values) and while i have read many recommendations e.g:
splitting of worksheets (not possible due to the nature of this file)
shorter formulas, (not possible)
tested on both 32 and 64 bit (performance is not notably different)
I was wondering if you guys came across any ways of optimising opening time for Excel without significantly altering the contents within in it, or any further suggestions.
Save it as an Excel Binary Workbook (.xlsb). You can retain macros, the filesize will be 25-35% of the original and many operations (not just opening/closing) will be faster.
Get rid of any volatile functions that are recalculating the worksheet unnecessarily. INDIRECT, OFFSET, ADDRESS, TODAY and NOW are among the list of volatile functions. Most can be replaced with non-volatile alternatives.
Improve the remaining calculation of the workbook by making worksheet formulas and functions more efficient. Help on this is available at Code Review - Excel, a StackExchange partner. No examples supplied so no specific help offered.
Improve any sub procedure cod run times at the same site. Large blocks should be processed 'in-memory' with arrays, not looped through cell-by-cell, etc. Again, no examples supplied so no specific help offered.
If you use corporate network try first downloading the file to you local computer and then opening.
It may also depend on existence of links to other files, try to reduce their number to minimum if there are any.
Nontheless, the volume of data in your file - is the main driver of opening time.
Everyone !
it is my first post here and as a novice I hope my question will make sense.
I'm a french intern working for a large firm and was assigned to the making of an "automated report" (I know, another one...).
The situation is pretty messy, each department generate reports for themselves with little to no constraints concerning the name, layout, size and data contained inside. (meaning that from one month to the other, each department may add or suppress an indicator, change the disposition of the data etc.)
I work for the performance and strategical division and need to create a four-table Excel file which would ideally be able to get the relevant data from the different files issued monthly. I cannot change the way files are updated on the intranet and my boss is clearly illiterate when it comes to computing.
Is it even possible for me (I do not know how to use VBA yet but I am a fast learner) to do this, while being transparent to her (zero or really easy manipulations), and adapting to the changing data-files format ?
Thank you in advance for any answer and sorry if i am not explaining myself properly.
I wish you all a great day !
Jules
In which formats would all the arbitrary files be?
In VBA you can open quite many file types and read the data if you just know the format and how data is organized.
If those files are in Excel files too, you can use Workbook.Open;
Dim wbReport As Workbook
Set wbReport = Workbooks.Open("ArbitraryDirectory\\ArbitraryfileName.xlsx")
Then use that workbook just like your main workbook;
OneOfYourFourTables.Cells([Row], [Column]) = _
wbReport.Sheets("TheArbitrarySheet").Cells([Row], [Column])
Or use Range objects and/or Copy methods. (I generally like to loop around the Cells()).
Currently we have a Excel VBA application, which consists of 25-30 Excel sheet (and all of those sheets all hidden and we do background processing on them and display it to VBA forms UI), and we have developed a UI using VB forms. But problem we are facing is whenever we click on Save button using this code:
ThisWorkbook.Save
But this saves entire workbook not an individual sheet, so even if we make changes in single sheet it saves entire workbook and this save processing makes very slow (since it needs to save all excel sheet containing lot of data unnecessary, even if there is no changes).
My question is is there any way we can save "only one sheet in a particular excel sheet" not an entire excel file?
Note: I am a Java developer and I worked on VBA before, But it was years back, and I have forgotten bit. Any guidance would be appreciated. Or any pointers on how to handle this situation would be appreciated. Please let me know if you need any more information, I can edit this question.
What I have tried already? I did a lot of research from yesterday, I searched in previous questions on SO, but didn't get any useful information. As per my research it says we cannot do this. Am I on right path?
The short answer is no. You cannot save a single worksheet at a time.
You may want to try to reduce the amount of data in the workbook. Try storing data in several workbooks and when it is needed, open that specific workbook, make the needed changes, and then close it.
If it is necessary to have access to all data at once then consider using access or some other database.
It is also possible that the sheets have "blank data". Cells that don't contain anything in them but excel thinks they do so when saving it tries to save way more than needed.
Assuming that it is the active worksheet that you want to save then you could do something like this:
ActiveSheet.Copy
ActiveWorkbook.Close True, "path"
This copies the active worksheet which creates a new workbook which will become the active workbook. Then just call the close method on that and give it a file name.
I think you should consider splitting your application into multiple workbooks:
The workbook that contains all the logic, user forms and programming code. This workbook handles all other workbooks as well as the displaying of it. Potentially, this could be even an "Application Specific Addin", that stays dormant but activates as soon as any of it's subsequent workbooks gets opened. For this architecture approach check out the section on "Application Specific Addins" in this link.
This workobook/add-in can also hide the other workbooks, so that the user will not notice it's multiple workbooks.
One or multiple data workbooks: Depending how interlinked the data is, you can separate this, e.g. in a "Sales data" workbook which contains the large database, as "Base data" workbook, that contains all the smaller data (e.g. products or stores tables).
This way, you can reduce the saving to the "relevant" sheets. However, of course this requires quite a bit of reprogramming - but it's worth the effort, as for instance it also allows to provide updates/bug fixes without having the transfer the data between versions, as you only need to distribute the the file with programming logic. :-)
If I need to automate a series a task on an excel sheet like
remove all rows where column 3 contains value "asdf"
remove column 7 and column 9
sort according to column 4
etc.
What is the easiest way of automating such tasks in excel? I think it would recording a macro but sometimes macro have to be edited a lot to actually make them work and even then macros stop if the excel sheet has a variation. Editing macro scripts could be a time taking process which becomes inefficient for such tasks. The automation is required since number of excel sheets will be a lot. Can you suggest an easier way ?
As long as, you have the activities defined - Macro is still the better thing to look for.
There could be some things that could change.
Please explain the problem with the help of code.
If you have defined the steps with a few variables, it should be easy to write a macro that wouldn't stop in case of variation.
Please post the code and describe in detail what you would want? which point does it stop, in case of variation? What would you like the code to do?
EDIT: Alternatively, you can write code in VB6/.net (c#/vb.net)/Python for automation.
If you record these steps using the macro recorder it will work fine, these are the ideal types of things for the macro recorder as the parameters (i.e. your sort by and delete conditions) are always the same. Just make sure that you always import/paste the data to the same place!
Thanks
Ross