TL;DR: probably Robert Browning and "Sordello".
This quote is commonly attributed to the German mathematician
“When I wrote this, only God and I understood what I was doing. Now, God only knows.”
― Karl Weierstrass
Some detailed research by Quote Investigator (which I found thanks to our comrades at HSM Stack Exchange, so hat-tip to them) has thrown up many different people who've said this or similar quotes:
This comical anecdote has an extensive history with similar comments attributed to Johann Paul Friedrich Richter, Jakob Böhme, Johann Gottlieb Fichte and others. Well-known writers such as Harriet Beecher Stowe, Mark Twain, and G. K. Chesterton were amused enough to record the remark.
The earliest instance they've managed to find was attributed to the German writer Johann Paul Friedrich Richter in an article of 1826:
The works of JOHN PAUL RICHTER are almost uninteresting to any but Germans, and even to some of them. A worthy German, just before RICHTER’S death, edited a complete edition of his works, in which one particular passage puzzled him. Determined to have it explained at the source, he went to JOHN PAUL himself, and asked him what was the meaning of the mysterious passage. JOHN PAUL’S reply was very German and characteristic. “My good friend,” said he, “when I wrote that passage, God and I knew what it meant. It is possible that God knows it still; but as for me, I have totally forgotten.”
-- 1826 August 9, The Morning Chronicle, Issue 17755, The Mirror of Fashion, Quote Page 3, Column 1, London, England. (19th Century British Newspapers: Gale)
Since then it's been attributed to a number of other writers, including other Germans such as Jakob Böhme and Johann Gottlieb Fichte. The first British poet found associated with this quote by QI was Robert Browning, in an article of 1890, concerning his poem "Sordello"; it's quite probable that this is the one that you heard about:
Mr. Browning himself, ‘in the philosophic afternoon of life,’ frankly confessed its difficulties, and referred to it with a grim smile as ‘the entirely unintelligible Sordello.’ And to an anxious admirer who asked him to explain its meaning he replied, ‘When I wrote it, only God and I knew; now God alone knows!’
-- 1890 July, The Church Quarterly Review, Volume 30, (Issue Start Page 273), Article III; Robert Browning, Start Page 313, Quote Page 319, Spottiswoode & Co., London.