According to the sequential accretion model, giant planet formation is based first on the formation of a solid core which, when massive enough, can gravitationally bind gas from the nebula to form the envelope. In order to trigger the accretion of gas, the core has to grow up to several Earth masses before the gas component of the protoplanetary disc dissipates. We compute the formation of planets, considering the oligarchic regime for the growth of the solid core. Embryos growing in the disc stir their neighbour planetesimals, exciting their relative velocities, which makes accretion more difficult. We compute the excitation state of planetesimals, as a result of stirring by forming planets, and gas-solid interactions. We find that the formation of giant planets is favoured by the accretion of small planetesimals, as their random velocities are more easily damped by the gas drag of the nebula. Moreover, the capture radius of a protoplanet with a (tiny) envelope is also larger for small planetesimals. However, planets migrate as a result of disc-planet angular momentum exchange, with important consequences for their survival: due to the slow growth of a protoplanet in the oligarchic regime, rapid inward type I migration has important implications on intermediate mass planets that have not started yet their runaway accretion phase of gas. Most of these planets are lost in the central star. Surviving planets have either masses below 10 ME or above several Jupiter masses. To form giant planets before the dissipation of the disc, small planetesimals (~ 0.1 km) have to be the major contributors of the solid accretion process. However, the combination of oligarchic growth and fast inward migration leads to the absence of intermediate mass planets. Other processes must therefore be at work in order to explain the population of extrasolar planets presently known.