I am replacing a ceiling fan+light unit. It is controlled by a on/off switch for the fan and a dimmer switch for the light unit. From the ceiling I have a bare wire, black, white, red wires. The fan has a white, black, blue, and green wires.
I,ll describe the process of elimination that ThreePhaseEel describes.
First, you connect earth to earth, because it's a world standard that green, green/yellow, or bare is always earth. So that's easy.
If neutral is present, it must be white. Neutral must by nature be present on both sides here, so the whites must be neutral. Connect them, done.
That leaves two colors from the wall and two from the fan. Colored wires must be hot. There are only 2 ways to hook them up. We're not sure, but it won't be destructive to try one way and see.
For your average fan+light combo:
Wire bare to green + the box grounding pigtail (should be green or bare as well), white to white, black to black, and red to blue.
If the dimmer controls the fan at that point:
If you find the dimmer switch controlling the fan at that point, undo the black and blue wires from the fan in the ceiling box and wire them black to blue and red to black.