msgbartop
Just another WordPress site
msgbarbottom

19 Jun 18 TDD in Excel




What is TDD?

Test-driven development (TDD) is a software development process that relies on the repetition of a very short development cycle: requirements are turned into very specific test cases, then the software is improved to pass the new tests, only” (Wikipedia)

We could think this refers only to programming/coding. I don’t think so.

How did I apply a version of TDD in Excel?

Theoretically, when we build an Exel model then it should be simple and easy to read.

However, life goes beyond the simplicity and readability rule because it is important to maintain the structure of the table and/or the importance of calculation speed.
If we use complicated formula, that should be protected or converted to values to ensure the formulas cannot be edited by those who are not familiar with it.

In any case, complicated formulas must be thoroughly tested.

These test cases were listed and the formula was copied to under one another to check different kinds of input values for the correct calculation.

For example, we would like to calculate the date of the first Monday of the first working week.
This is a very simple example, I use this method for much more complicated calculations.

The trick is the week that counts as the first workweek is the one that contains the first Thursday of the year.

I listed years where the first days of January are on different days so that all of the 7 cases are correct. (I added the correct result to compare the calculated results with)

And it seems that there was a need for it because a bad calculation can give a good result.

If I had tested it only till 2020, I could think that everything is good in the first run.
If I had tested it till 2025, I would think the second run is correct.
Thus, the third run gave a result that is good for each case.

For a perfect solution, it would also be worth dealing with invalid inputs, eg. someone makes a mistake and writes a date instead of a year, or writes a text, an error or a fraction.



 

16 Feb 09 Relative range names in practice

With range names you can do big tricks with excel.I will show you one of these tricks today:When you define a range name, then excel will propose the absolute cell reference as default.But you can use a relative or a mixed reference too.The active cell is the starting point.You have to create your reference like you would write into that cell.My trick is:

  1. Select A2 cell.
  2. Choose Insert –> Name –> Define
  3. Type a name for the range: “Last”
  4. Write in the refers to box “=A1″ without quotes and without dollar signs.
  5. Give a name to this range, for example “last”

This range name will refer to the upper cell to the current position.It can be used like this:

=SUM(B2:Last)

will give you a dynamic range that will grow or shrink when you insert or delete some rows, even if the deleted row is the last row from the range.This is a perfect solution.If you insert multiple rows and don’t fill every cell, the normal reference will not upgrade, the relative name will always work.

28 Jan 09 VBA Error Handling with line numbers

Sometimes it is easier to find an error if we know the code line where the error occurred. I have a method to show this in an error message.This is a light version of my error handler and focuses only to the line number of the error.There is a variable called “erl” which contains the line number of the error, so we can use it in the error message:

MsgBox Err.Number & " - " & Erl & " - " Err.Description

But this will show 0 instead of the line number if we didn’t put numbers at the beginning of the rows.Dick Kusleika wrote about the MZ Tools, and MZTools is a great tool for this too.There is an “add line number” icon on the toolbar which made the line numbering in my stead.

Add Line Number Icon

Add Line Number Icon

Voila, it is done, and we can use it.