I cannot comment about others but normally I am always in a hurry to write macro(s) so that I can finish task in hand as soon as possible. In this process I loose track of functions/methods I am using to finish the task. Does it matter? As goal is to finish the task. Let's go through one example.
I am adding two integers, in this example 1+1, 10000 times. I will perform this task using two ways. First way, I will use excel's Autofill method. Second way, I will use a For loop to iterate the addition operation 10000 times. Now, check this out.Time taken by:
1. Autofill function - 0.02s
2. For loop - 5.98s
So, 5.98/0.02 = 299 .. First method was 299 times faster than second method.
Surprised !! .. Imagine if you perform a complex operation involving functions like VLOOKUP, FIND, MATCH and INDEX on a huge dataset 10000 times then what would time delta be ?
Yes, you got it. Performance optimization is as important as finishing the task. We normally work with huge datasets hence how we manipulate data becomes equally important. Once you figure out the logic for a particular problem, take your time to write the program. What's the point of automation if a task requires 5 minutes and your code is taking 10-15 minutes to finish the same task š
Once I wrote a huge (in terms of number of lines) macro. The macro took almost an hour. I figured out few changes but forgot where to make them as I had not added comments š . Now, I am doing some part of that activity manually.
So, try to optimize your code as much as possible so that it takes less time to execute. The attached document shows subroutines used for both the ways discussed above.
Please find the below URL:
https://learn.microsoft.com/en-us/office/vba/excel/concepts/excel-performance/excel-tips-for-optimizing-performance-obstructions
Remember:
First, solve the problem. Then, write the code. ā John Johnson
Make it work, make it right, make it fast. ā Kent Beck
Happy Learning !!
excel microsoft msexcel vba