Can a rogue sneak attack with a ranged weapon? IIRC, yes, if the target is within 30'.
Can a rogue use a ranged weapon to flank? No. You can only flank when you threaten the area the target occupies. Ranged weapons do not threaten an area.
Thus, you cannot flank and sneak attack with a ranged weapon. If you are using a ranged weapon, you must find some way to deny the target's Dex Bonus to AC to sneak attack.