Yields of prompt and non-prompt J/ψ, as well as ^Y(1S) mesons, are measured by the CMS experiment via their μ^+μ^− decays in PbPb and pp collisions at √s_(NN)=276 TeV for quarkonium rapidity |y| < 2.4. Differential cross sections and nuclear modification factors are reported as functions of y and transverse momentum p_T, as well as collision centrality. For prompt J/ψ with relatively high p_T (6.5 < p_T < 30 GeV/c), a strong, centrality-dependent suppression is observed in PbPb collisions, compared to the yield in pp collisions scaled by the number of inelastic nucleon-nucleon collisions. In the same kinematic range, a suppression of non-prompt J/ψ, which is sensitive to the in-medium b-quark energy loss, is measured for the first time. Also the low-p_T ^Y(1S) mesons are suppressed in PbPb collisions