You could try the following:
Add instance variables "directionX" and "directionY" to the block
Set those variables at the start to 0
On moving block:
enable bullet behaviour;
if direction = up set directionY to -1,
if direction = down set directionY to 1,
if direction = left set directionX to -1,
if direction = right set directionX to 1
On block overlapping with wall:
disable bullet behaviour;
Set block (X,Y) to ((block.directionX*(wall.width+block.width)/2)+wall.X ,(block.directionY*(wall.height+block.height)/2)+wall.Y);
Set block.directionX and block.directionY to 0
This method assumes that your blocks and walls are positioned on a grid.