Margarine and vegetable oil start out as the same thing. Vegetable oil is naturally liquid and when it is processed through hydrogenation, it becomes solid margarine. Hydrogenation adds hydrogen bonds and creates "trans" molecules called "trans fats".
Hydrogenation is a chemical process usually done using a metal catalyst like nickel. When oil is hydrogenated, hydrogen molecules are added, altering the configuration of other molecules in the oil. The molecules' configuration changes from a "cis" to a "trans" state – hence the name trans fats. The body has a hard time processing these fats, which is why margarine is now considered bad for you.
Liquid vegetable oil becomes solid margarine because of the hydrogenation process. When the molecules are changed from cis to trans, they can no longer lay flat. If you think of oil as spaghetti, then margarine would be macaroni; the molecules no longer fit together. These misfit molecules also have a higher melting point, which means that it takes less heat to liquefy oil than it would margarine. At room temperature, oil remains liquid because of its lower melting point, and margarine is solid because of its higher one. If deciding between using oil or margarine, oil is better because it's less processed. If you want something smooth and spreadable, butter is a better choice as it does not contain trans fats.