VBA Best Practice There is a lot of information floating around about how to get various things done in VBA, how to make the best use, or sometimes just the most use of VBA and Excel. This section aims to add an element of Quality and Best Practices. These are just general guidelines, a professional developer will always assess the options and make the appropriate choice in their specific situation. These suggestions are specific to Excel VBA in commercial settings, many will not translate to other technologies or other settings. VBA Best Practice Series High Quality Code - Excel 2- Pulling Range.Value or Range.Formula into a variant is much faster than looping the cells.
- Use worksheet.cells(r,c) structure rather than range(""A"" & someNumber)
- Be consistent how you use ranges (between Range() and Cells() for example)
- Remember the power of R1C1 notation
- Its often easier to set the formulaR1C1 than the formula of a range.
- If distributing code with references, consider making it late bound.
- Use standard environment management routines (calc, events etc there is one here)
- Use Excel functionality wherever possible
- Use doEvents where needed
- Work upwards when deleting rows, otherwise counters get messed up
- Watch for inadvertently firing events
- don't hog the onCalculate event
|
|
Upcoming Events:
25 January 2012 - UK Excel Developer Conference - London
Products for sale:
AltFileSearch

New information about the missing FileSearch feature in Office 2007 and details of our pragmatic solution (Current price GBP 30.00)
wsUnprotector
Instant Excel worksheet protection remover and password recovery (Current price GBP 15.00)
Classic Ribbon Tab
Add Excel 97/2000/2002/2003 compatible menu structure to Excel 2007
(Current Price GBP 10.00)
Products coming soon:
Link Manager
(Find and control external links in Excel Workbooks)
Due by Q1 2111.
XLAnalyst Pro
(Excel VBA based spreadsheet auditing tool)
Due before the end of 2111. |