Visiting Lübeck's Dance of Death was a natural part of an educational journey and since Hans Christian Andersen travelled abroad 30 times, it was inevitable that their paths would cross.
Hans Christian Andersen took a trip to the Harz in Northern Germany from 16/5 to 24/6 1831. He went through Lübeck both on the outward and homeward journey, but he was too busy griping about his bad teeth to write anything particular in his diary.
Nevertheless, he was in St. Mary's Church because in his travelogue "Shadow Pictures from a Journey to the Harz Mountains and Saxon Switzerland, etc etc" (published September the same year) there's a splendid description of the dance of death:
In St. Mary's Church I saw the famed astronomical clock-
In 1833 he received a travel grant and embarked on a long trip (16 months) for Southern Europe and April 23rd he wrote: "The sail was boring, my spirits low; At 11 o'clock we were in Lübeck, everything seemed familiar to me from the previous time". We are not told whether "everything" includes St. Mary's Church.
In 1852 Hans Christian Andersen sailed down the Trave River again, bound for Lübeck, but apparently he had forgotten all about the "boring sail" in 1833 for he wrote May 17th: "The Trave meanders a lot, but did not make the impression of beauty as when I came here for the first time in 1831 (for 21 years I haven't been here and this was then my first trip abroad)". In Lübeck he went "to the organist and with him into the St. Mary's Church [...] Saw the death dance, Death looks very jolly".
In the novel "Only a Fiddler" from 1837, Lübeck's dance of death is featured prominently. The protagonist is a young boy, who happens to have the same name as the author:
When Christian had entered, the door was closed again.
" O Death, this art how can I know?
Christian looked at the figures in the pictures, and it oc-
[the godfather then teaches Christian to play the fiddle]
Nearly a whole hour did the first lesson last. The god-
It's less than clear, which "colored prints" Hans Christian Andersen is referring to. Since the number of pictures (5) corresponds to the number of dancers - Death, pope, emperor, maiden and infant - it sounds as if there's one person per picture.
The dance of death in St. Mary's Church in Lübeck has been reproduced several times, but usually in the form of one long chain-dance. A going through of all the various prints can be found in the book Ihr müßt alle nach meiner Pfeife tanzen pp. 83-135 and in Christa Pieske's article: "Die graphischen Wiedergaben des Totentanzes von Bernt Notke" in Philobiblon 1968, pp. 82-104. See the following page for several reproductions of the painting.
The Danish Royal Library's site has many of Hans Christian Andersen's fairy tales and novels (in Danish) - including Skyggebilleder af en Reise til Harzen and Kun en Spillemand. The translations on the present page are taken from Hurd and Houghton's Edition (New York, 1870-1).
The dairies of Hans Christian Andersen were translated by Patricia L. Conroy and Sven H. Rossel, University of Washington Press. Seattle & London, 1990 (the quotes on the present page however, are my own translations).
You can see Hans Christian Andersen's handwritten notes from his first trip to the Harz in facsimile on the Danish Royal Library's homepage about manuscripts. Hans Christian Andersen's notes are, of course, in Danish, but since his handwriting is completely illegible, you'll understand as much as any Dane. The entire text from Hans Christian Andersen's diaries is available (in Danish) at the Danish Royal Library's homepage about Hans Christian Andersen.
Footnotes: (1) (2) (3)