The hot source is spliced to the black, fan wire and the black wire running to the dimmer. At the other end, the black cable wire is spliced to one of the hot dimmer wires, it doesn’t matter which one. The other dimmer wire is spliced to the red wire in the switch box which is spliced to the blue, light wire at the other end.
Run the cable through the clamp and tighten it down. Splice the cable wires to the fan wires using a pigtail splice and a wire nut. Connect the ground to the grounding terminal in the connection box and the ground wire from the fan, if there is one.
This diagram illustrates wiring a GFCI receptacle and light switch in the same outlet box, a common arrangement in a bathroom with limited space. The hot source is spliced to the LINE terminal on the receptacle and to the bottom terminal on the light switch. The neutral and ground wires are spliced together and run to each device in the circuit.
This diagram illustrates a switch and receptacle in the same outlet box located in the middle of the circuit. This wiring allows the electricity to continue from the receptacle, on to any other outlets in the circuit and it provides a switch to control a light fixture or other load, such as another receptacle or a fan.