The answer above is absolutely correct. But when I read it, I had a hard time finding the answer. I'm going to be more explicit, but I'm not really saying anything much different than she is.
What cheers the speaker up is when he thinks of his "dear friend." As he says, if he thinks of the "dear friend" all his sorrows go away. This is in the last two lines (the couplet) of the sonnet.
So the idea of the poem is that the speaker is sad about a lot of things from the past -- friends who have died, things he wanted but did not get, time he wasted. But once he thinks of his "dear friend" he feels better.
In William Shakespeare's Sonnet 30, "When to the Sessions of Sweet Silent Thought," the speaker acts as a judge in his nostalgia, summoning "remembrance of things past"; recalling his losses, the speaker seems to pay again for them:
And weep afresh love's long since cancelled woe,/And moan the expense of many a vanish'd sight/Then can I grieve at grievances foregone/And heavily from woe to woe tell o'er/The sad account of fore bemoaned moan....
But, somehow by thinking of the fair youth, "all losses are restor'd and sorrows end." However, it is odd that this new relationship compensates for the dead ones. Perhaps, in by reflecting upon his melancholic memories, the speaker is reconciled by the friendship and love of the youth.
Interestingly, the line "rememberance of things past" was taken as the English title of the translation of the novel of the great French writer, Marcel Proust.
Sonnet 30 is very similar to Sonnet 29. Shakespeare begins #29 by describing his depressed mood and unpleasant thoughts. Then, rather than using a mere closing couplet to describe how remembering his friend cheers him up, he uses a full quatrain and a closing couplet:
Yet in these thoughts myself almost despising,
Haply I think on thee,--and then my state
(Like to the lark at break of day arising
From sullen earth) sings hymns at heaven's gate;
For thy sweet love remember'd such wealth brings,
That then I scorn to change my state with kings.