All perfect praise be to Allah, The Lord of the Worlds, and may His peace and blessings be upon our Prophet Muhammad and upon all his family and companions.
A vow doesn`t take place unless it is taken in a binding statement, such as: I vow that I will do so and so……Whereas the statement "I will slaughter a sheep to drive away affliction," isn`t an obligation; rather, it is a future plan.
However, if you (asker) intended your statement as a vow, many scholars have said that it becomes binding and must be fulfilled, but it isn`t permissible for you or any of your dependants to eat from that animal; rather, you must distribute it among the poor and needy.
However, if you didn`t intend to take a vow then you aren`t obligated to slaughter that sheep, but it is recommended that you do, and in this case it is permissible for you and your dependants to eat from its meat.
Al-Imam Al-Ramli (May Allah have mercy on him) said: "It is when a person says: If Allah recovers my son from his illness, I will build a mosque or a house for someone. This doesn`t take the ruling of an oath because it is just a promise. However, if it was intended as an obligation, some scholars considered it a vow. {Nehayat Al-Mohtaj, 8/221}.
It is worth pointing out that slaughtering animals to please Allah and feed the poor and needy is among the best acts of devotion to thank Allah for his graces. However, there is no evidence in Sharia indicating that such an act stops affliction from taking place since the latter is a universal law legislated by Allah for a great wisdom. Moreover, it suffices to say that Prophet Mohammad (PBUH) was visited with affliction but he exercised patience and sufficed with Allah`s reward. And Allah knows best.