@Hnx What I see in your worksheet, and what I see in the worksheet provided by Preben are the same, but here is an issue with what you are doing, besides using 2D input mode.
You are trying to write code inline using the if then statement, and using the Enter key to move to the next line. This is a problem. Two easy ways to get around this. Write your code in an external editor (like Notepad++), which is what I did, or use Shift+Enter key to advance to the next line, when writing code using if statements, else, for loops, ...
See your worksheet in the attachment, where the code that Preben provided is in one region without any line breaks.