Avoid Hardcodes in Formulas
- 04:17
Understand the importance of avoiding hardcodes
Glossary
Dynamic FormulasTranscript
Avoiding hard codes in formulas is of paramount importance. Putting hard codes in is very quick and easy. Imagine I had a profit of 10 and I wanted to know the tax on it. Well, I could write a formula of 10 times by 30%. If 30% was the tax rate, the answer would be three. It's quick, but it's inflexible. If the tax rate changed, every formula with a tax rate would have to be found manually. Imagine you had thousands of these formulas and had 30% written into each one. Every formula would have to be found and then changed. Changed. Instead, we put each hard code in its own cell. So for example, I put the profit of 10 in cell A1 and the tax rate of 30% into B1. Then my formula for the tax would just be A1 times by B1. Let's look at another example in Excel here I've got three costs, salaries, purchases, and expenses, and they've all been given in pounds 180 and 60. These numbers have been hard coded in, and I know they've been hard coded because the formatting that's been used is blue, which indicates a hard coded number. I now want to know what the figures in US dollars are. Let's say the exchange rate is $1.30 per pound. So to work out the salaries in US dollars I type equals go select cell B2, which has 100 in it, and I multiply by the exchange rate of 1.3 and that gives me 130. I do exactly the same thing for purchases. So the 80 multiplied by 1.3 and expenses.
Great. Now I've got US dollar figures. The problem is what happens if the exchange rate changes to 1.4? I may have thousands of cells with US dollar figures in them, and I would need to go in and manually change the 1.3 exchange rate to 1.4. That's gonna take far too long and it's a very inefficient way of using Excel. Instead, it would be much better to have the exchange rate hard coded in its own cell. I'm gonna put that in B6.
I am going to change the formatting of that 1.4 to the dark blue to indicate it's a hard code. So if I go to the home ribbon and I go to cell styles, I will select hard coded. Now I can rewrite my formulas and link to that exchange rate. So I'm going to select cell B2, the a hundred salaries, and I'm going to multiply that by the exchange rate in B6, and I'm going to do the same thing for the purchases and expenses.
The good news is if the exchange rate subsequently changes, all of those cells will automatically update. So if I type 1.2 in as the exchange rate, have a look at what happens to those numbers in column C. They should automatically update, which they do. Fantastic.