All perfect praise be to Allah, the Lord of the worlds. I testify that there is none worthy of worship except Allah, and that Muhammad is His Slave and Messenger.
It was reported in the Sunan An-Nasaa'i and others that 'Abdullah ibn 'Amr said: "The Messenger of Allah said: 'There are two qualities which no Muslim attains but he will enter Paradise; they are easy, but those who do them are few.' He ('Abdullah) said: The Messenger of Allah then said: 'The five daily prayers: if one, after each prayer, glorifies Allah (saying 'Subhanallah) ten times and praises Him (saying 'Al-hamdu lillaah) ten times and magnifies Him (saying Allahu Akbar) ten times, then this is one hundred and fifty (rewards) uttered by the tongue but are one thousand five hundred rewards in the scale (of Allah).' ('Abdullah) then said: 'I saw the Messenger of Allah, sallallaahu 'alayhi wa sallam, counting them on his hands (finger joints). He continued saying: 'And one says, when he retires to his bed, 'Subhanallah thirty-three times and 'Al-hamdu lillaah thirty-three times and Allahu Akbar thirty-four times, that is counted as one hundred (rewards uttered by) the tongue but are one thousand (rewards) in the scale (of Allah).' He then asked: 'Who amongst you commits two thousand five hundred bad deeds in a day and a night!?' It was said: 'O Messenger of Allah, how can a person not persist in doing that!?' He said: 'The devil comes to one of you when he is praying and whispers: 'Remember such and such, remember such and such, and he comes to him when he is in bed and makes him fall asleep.'" [Classified as authentic by Shaykh Al-Albaani]
Al-Munaawi said in Faydh Al-Qadeer: "The term, 'So who amongst you commits two thousand five hundred bad deeds in a day and a night!?' means that if a person says these words after the prayers and when going to sleep, then a two thousand and five hundred rewards will be counted for him, and by every good deed, a bad deed will be erased from him. So whoever does this every day and night will be forgiven." [End of quote]
It appears from this that the one who does a bad deed, that can be erased by the virtue of performing a good deed, and then performs a good deed thereafter, then the bad deed will be erased from him by the grace of Allah.
Allah knows best.