In 5e, there are two ways that rogues get sneak attack (outside of specific subclass features): 1) You have advantage on the attack. 2) You have an ally within 5' of your target and you don't have disadvantage on the attack.
It doesn't matter if your attack is melee or ranged, but if it's melee, you have to be using a finesse weapon.