This is b'coz the Cells index can't be cells(0,1) which you have defined asCells(rIndex, 1) where rIndex is 0chnage the r index to 1 to 17 it will work