Developing a Checklist to Increase Efficiency of VBA Code

Author(s)

Medland S1, Davies H2, Butler K3
1York Health Economics Consortium Ltd, Cardiff, CRF, UK, 2York Health Economics Consortium Ltd, York, York, UK, 3York Health Economics Consortium Ltd, York, YOR, UK

OBJECTIVES: Several Health Technology Agency bodies specify a model run time in their pharmacoeconomic guidelines. It is preferable to write code efficiently given time constraints faced by evidence reviewers and this research aims to give advice on writing bespoke, efficient Visual Basic for Applications (VBA) code.

METHODS: A model with a slow deterministic sensitivity analysis (DSA) was selected for review. The modeller observed areas where the code efficiency could be improved and developed a checklist. The code was subsequently rewritten. The number of lines of code and average run time of the original and new code were compared.

RESULTS: Utilising loops rather than writing bespoke code for each task will shorten the code length. If a task is repeated in the code, custom functions and subroutines can be used within a module and cell ranges from the worksheet can be assigned to a defined variable. Option explicit should always be used to ensure all variables are defined to prevent errors. The choice of variable type is important; “strings” and “doubles” take up less storage space than “variants”. Using defined variables decreases interaction between the worksheet and the code and, therefore, run time. Other ways to reduce interaction include avoiding “.select”, “.copy” and “.pastespecial”, switching off worksheet updates and only calculating the model when necessary. The length of the new code was 89.7% shorter than the original (244 vs. 2,372 lines). Average run time, over four runs, for the new code was 78.2% shorter than the original (11.01 vs. 50.59 seconds).

CONCLUSIONS: The increasing size and complexity of economic models requires efficient use of VBA code. The use of these principals can reduce the time taken to conduct and adapt an analysis and facilitate review by increasing readability and reducing code length.

Conference/Value in Health Info

2023-11, ISPOR Europe 2023, Copenhagen, Denmark

Value in Health, Volume 26, Issue 11, S2 (December 2023)

Code

MSR128

Topic

Methodological & Statistical Research

Disease

No Additional Disease & Conditions/Specialized Treatment Areas

Explore Related HEOR by Topic


Your browser is out-of-date

ISPOR recommends that you update your browser for more security, speed and the best experience on ispor.org. Update my browser now

×