1. Derailleur has to be in whichever cog it naturally goes to when the cable is disconnected. Usually that's the smallest.
2. The shifter has to be in the position that corresponds to that cog.
3. The cable has to be pulled taut but not real tight. I find it easier to use a needlenose pliers to tension it. After tightening the anchor bolt you can use the barrel adjuster as necessary to fin tune the cable tension.
4. IMPORTANT. If your rear derailleur was working properly before you disconnected the cable, messing with it's limit screws is never necessary.