Magnetic fields are found to have an inherent capability of acting against gravity. An important question posed in the literature is whether presence of a magnetic field can alter the dynamics of a gravitational collapse and prevent the final formation of a singularity. Promising conclusions regarding this have been found in a few recent works considering nearly homogeneous models. However, whether this can happen in realistic collapse scenarios is still not very clear and remains an open problem.In the present work we investigate the role of magnetic fields in the evolution of inhomogeneous cylindrically symmetric models. We use an approach based on the Raychaudhuri equation for such an analysis. We show that it is quite possible for the magnetic field to avert the gravitational collapse in these models.