Sub s() i = 22 Do While Cells(20, i) <> "" j = 22 Do While Cells(21, j) <> "" Cells(i, j) = (10 + Cells(20, i) - Cells(21, j)) Mod 10 j = j + 1 Loop i = i + 1 LoopEnd Sub