If replacing a rim and using the same brand and model rim but reusing the same hub and spokes, use tape to temporarily attach new rim to the old rim, taking care to put the valve holes next to each other. Loosen all spoke nipples a few turns. Then move one spoke at a time from the old rim to the new. You will figure out immediately which spokes transfer from rim to rim easiest to start with, work with the easiest ones first.
A spoke that is too long can either run out of thread on the nipple, preventing adequate tension and/or creating an opportunity for puncture if the spoke protudes through the rim tape. But, if your spokes are a few mm too short you probably still have enough thread within the nipple to provide adequate tension. Thus, if your spokes are out of specified length by a mm or two, shorter may be better than longer.
I personally do not own the tools to measure ERD, I go to a local bike shop to buy my spokes. They are kind enough to measure my rims and flanges for me. Not all bike shops will take the measurements and perform the calculations, perhaps I am lucky that a local shop will do that for me when I buy spokes from them.