It looks like you're going to the last row available and then trying to go one past it, causing an error. Your best bet at debugging it, however, is to split that complex statement up into its constituents, one per line - that way you can see at which point in the statement it is failing.