A macro can run without an error and still change the wrong cells. Debugging starts with the requested result: identify the output range, check every input address, then follow the statements with a small example.
Loop boundaries are inclusive in VBA. For r = 2 To 4 reaches the final row 4. Cells(row, column) expects the row first, so swapping its arguments can silently write across a row instead of down a column. A Do While loop must change the variable used in its condition or it will keep running.
Use the Visual Basic editor to repair the smallest incorrect statement, then run the procedure again. Inspect the cells at the edges of the intended range. A first row that looks right is weak evidence if the final row was skipped or an unrelated cell was overwritten.