Instead of a code why dont u use function Row()? Choose the last column and inthe column next to it write "=ROW(cell from previous column)"