Dust attenuation shapes the spectral energy distribution of galaxies. It is particularly true for dusty galaxies in which stars experience a heavy attenuation. The combination of UV-to-IR photometry with the spectroscopic measurement of the H$alpha$ recombination line helps to quantify dust attenuation of the whole stellar population and its wavelength dependence. We selected an IR complete sample of galaxies in the COSMOS 3D-HST CANDELS field detected with the Herschel satellite with a signal to noise ratio larger than five. Optical to NIR photometry is available as well as NIR spectroscopy for each source. We reduced the sample to the redshift range $0.6 < z < 1.6$ to include the H$alpha$ line in the G141 grism spectra. We have used a new version of the CIGALE code to fit simultaneously the continuum and H$alpha$ line emission of the 34 selected galaxies. Using flexible attenuation laws with free parameters, we are able to measure the shape of the attenuation curve for each galaxy as well as the amount of attenuation of each stellar population, the former being in general steeper than the starburst law in the UV-optical with a large variation of the slope among galaxies. The attenuation of young stars or nebular continuum is found on average about twice the attenuation affecting older stars, again with a large variation. Our model with power-laws, based on a modification of the Charlot and Fall recipe, gives results in better agreement with the radiative transfer models than the global modification of the slope of the Calzetti law.