I have just typed out very long code in Excel that just repeats itself 17 times, but each time with different cell references. Is there a more concise way of writing my code, perhaps by using another column of cells?

The code that is repeated is:


This figure is then added on to other figures which are obtained from columns further along. I am finding the real value of the cost of alien clearing in 2014 prices over a number of years. In the first example, the column X2 holds the nominal value of the alien clearing in year YEAR(Y2), array $EU$3:$FH$57 holds the CPI data, with the year in column 1 (EU) and the average index for each year in column 14 (FH). $FH$57 holds the CPI index for 2014.

I copied the following formula down an entire column to get the real value of clearing for a number of different projects:


  • \$\begingroup\$ Use a for-loop. \$\endgroup\$
    – barq
    Feb 13, 2015 at 14:02

1 Answer 1


Why not create user-defined functions? User-defined functions can be used in the same flavor as Excel functions (i.e. =CUSTOM_FUNC_FOO(A1:B2)), and be composed similarly in formulas. There are many advantages: better readability (because the logic is encapsulated), better algorithms (because you gain access to programming structures). The downside is that you need to write a bit of VBA, which you may not be familiar with (it's not complicated though).

  • \$\begingroup\$ I don't know Visual Basic. If I want to learn Visual Basic, should I buy a book? Or are there short courses offered by the Microsoft academy? \$\endgroup\$
    – ahorn
    Feb 14, 2015 at 20:07
  • 1
    \$\begingroup\$ Hello. I'd suggest you simply try free online tutorials to learn basics, then consider books or courses if you want/need to further deepen your acquired knowledge. First focus on the following 4 subjects: VBA programming constructs (sub, function, data types, arrays, if/then/else, select/case, loops), Excel object model (how to create/write/read to/from sheets and ranges), macro recording (actions manually done with the mouse/keyboard are translated into VBA code, which can help in discovering useful Excel objects), and finally the difference between VBA and other VB-based technologies :) \$\endgroup\$
    – Elegie
    Feb 15, 2015 at 8:17
  • 1
    \$\begingroup\$ Starting later this year, the Excel Lambda function (now only in beta versions) will allow you to create these kind of functions, without using VBA! \$\endgroup\$ Jun 14, 2021 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.