Grid range generating code