I decided to fast today, to make up a day when I did not fast during Ramadan. But then I forgot that I had decided to do that, and when I woke up after Fajr I ate and drank. Then my grandmother reminded me that I was supposed to fast that day to make up a missed fast, so I refrained from eating and drinking until sunset. Will that day be counted as a fast, because I completed it until sunset, or not?
If a person eats or drinks because he forgot, when he was fasting, then his fast is still valid, because of the report narrated by Muslim (1952) from the hadeeth of Abu Hurayrah (may Allah be pleased with him), who said: The Messenger of Allah (blessings and peace of Allah be upon him) said: “Whoever forgets, when he is fasting, and eats or drinks, let him complete his fast, for it is only Allah Who has fed him and given him to drink.”
There is no difference, in that regard, between a Ramadan fast or a make-up fast, or a fast in fulfilment of a vow, or a naafil (supererogatory) fast, because of the general meaning of the text.
Imam ash-Shaafa‘i (may Allah have mercy on him) said:
If the fasting person eats or drinks during Ramadan, or during a fast in fulfilment of a vow, or an expiatory fast, or a fast that is obligatory for some other reason, or a voluntary fast, because he forgot, then his fast is still complete and he does not have to make it up.
End quote from al-Umm by ash-Shaafa‘i (2/75)
Shaykh ‘Abd al-‘Azeez ibn Baaz (may Allah have mercy on him) said:
That also includes a case where a person eats due to forgetting during a fast in Ramadan or otherwise, whether the fast is voluntary, or to make up a missed fast, or in fulfilment of a vow. If he ate because he forgot, or he drank because he forgot, or he had intercourse because he forgot, he does not have to do anything, because the Prophet (blessings and peace of Allah be upon him) said: “Whoever forgets, when he is fasting, and eats or drinks, let him complete his fast, for it is only Allah Who has fed him and given him to drink.”.
End quote from Fataawa Noor ‘ala ad-Darb by Ibn Baaz (16/479)
Based on that, so long as you formed the intention to observe the make-up fast from the night before, then the fast is valid and counts as making up for a missed fast in Ramadan; it does not matter that you ate and drank because you forgot.
And Allah knows best.