| Start |
|---|
| Disabling Worksheet Updating Disabling calculation of the worksheet can decrease running time of the macro significantly. Moreover, disabling events, screen updating and page breaks would be beneficial. Following For optimization follow the below pseudo-code: |
| Optimizing Error Search by Extended Debugging Using Line Numbers ... and documenting them in case of error ("The importance of seeing Erl") Detecting which line raises an error is a substantial part of any debugging and narrows the search for the cause. To document identified error lines with a short description completes a successful error tracking, at best together with the names of module and procedure. The example below saves these data to a log file. Back ground The error object returns error number (Err.Number) and error description (Err.Description), but doesn't explicitly respond to the question where to locate the error. The Erl function, however, does, but on condition that you add *line numbers ) to the code (BTW one of several other concessions to former Basic times). If there are no error lines at all, then the Erl function returns 0, if numbering is incomplete you'll get the procedure's last preceding line number. 'Additional Code to show log file |
| Checking time of execution Different procedures can give out the same result, but they would use different processing time. In order to check out which one is faster, a code like this can be used: MicroTimer (opens new window): |
| Using With blocks Using with blocks can accelerate the process of running a macro. Instead writing a range, chart name, worksheet, etc. you can use with-blocks like below; Which is faster than this: Notes: Nesting Example: This example uses the With statement to execute a series of statements on a single object. More Info on MSDN (opens new window) |
| Row Deletion - Performance Example: |
| Disabling All Excel Functionality Before executing large macros The procedures bellow will temporarily disable all Excel features at WorkBook and WorkSheet level
Restore all Excel settings to default Remarks*) Line numbers represent are integers, that is a signed 16 bit data type in the range of -32,768 to 32,767, otherwise you produce an overflow. Usually line numbers are inserted in steps of 10 over a part of the code or all procedures of a module as a whole. |
Read Article
https://develop.horje.com/learn/1434/reference