R5 train from Pl. Espanya to Montserrat. FGC trains. Línia Barcelona-Vallès. Get off at either Aeri de Montserrat station to connect with
Aeri de Montserrat cable car to Montserrat. Or stay on the train past the cable car station and get off at Monistrol de Montserrat station, where you can transfer to the Cremallera Rack-rail train which takes you from the valley up to Montserrat monastery area.
You can buy a combined tickets. See how to get to
Montserrat from Barcelona.