If you find yourself in the unenviable position of flanking while holding a ranged weapon, you may indeed flank. The only requirements in this instance are:
Opposite Sides: To flank an enemy, you and an ally must be adjacent to the enemy and on opposite sides or corners of the enemy’s space. When in doubt about whether two characters flank an enemy, trace an imaginary line between the centers of the characters’ squares. If the line passes through opposite sides or corners of the enemy’s space, the enemy is flanked.
Must Be Able to Attack: You and your ally must be able to attack the enemy, whether you’re armed or unarmed. If there’s no line of effect between your enemy and either you or your ally, you don’t flank. If you’re affected by an effect that prevents you from taking actions, you don’t flank.
As flanking with a ranged weapon is generally a painful choice, I'm not sure why this situation would naturally arise, but when it does, you certainly are able to.
The wording is a bit looser in 3.5
When in doubt about whether two friendly characters flank an opponent in the middle, trace an imaginary line between the two friendly characters’ centers. If the line passes through opposite borders of the opponent’s space (including corners of those borders), then the opponent is flanked.
Only a creature or character that threatens the defender can help an attacker get a flanking bonus.
Given that the ranged weapon could certainly be used as an improvised melee weapon, there's no inherent reason why they wouldn't count as threatening. However, a GM could rule otherwise.