Madrid has lots and lots of 24 hour pharmacies--many more than any American city that I ever lived in--especially in the center of town. You can find a list of them in the newspaper. Sometimes you have to ring a bell and they will come to the door and find out what you need.