The correct size bike is always extremely important, you absolutely have to be comfortable and confident on it.
There's really no substitute for trying before you buy, not just sitting on it in the shop but a good test ride.
I always think if you can adjust the seat so it's a couple of inches too low and you are also able to adjust it so it's an inch or two too high you have a good chance of finding a sweet spot somewhere in between.
You can then do a bit of fine tuning with handlebar angle, handlebar stem length and reach, saddle angle, also the saddle will usually slide backward and forward.
It's an inexact science and as Neal says, leg length is a big factor.
Dave.