The only problem now was that when I entered data into A1 to A9 I got
the Runtime error "91": Object variable or With variable not set.
To overcome this, in the beginning I've added the line "On Error GoTo
HERE:" and just before "End Sub" I've added the line "HERE:".
Now it apparently looks fine.