• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

7. Macro Hacks > 64. Optimize Your VBA Code

Optimize Your VBA Code

As you create more complex macros, minor delays caused by poor coding can really add up. This hack will help your VBA code run faster.

This hack demonstrates six specific programmatic techniques you can apply to accelerate your code. The improvement can range from modest increases to increases of several orders of magnitude in performance.

Use Integer Division

Your application probably performs a majority of its division operations on integer values. Many developers use the slash (/) operator to divide two numbers, but this operator is optimized for floating-point division. If you divide integers, you should use the backslash (\) operator instead. With \, Word works at the integer level instead of the floating-point level, so computation happens faster. (Of course, this is useful only if you assign the results of the division operation to an integer. If you care about the fractional portion of the division, you need to use floating-point math and the / operator.) For example, instead of:


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint