I would recommend re-framing the problem to better map to the physics of weapons. The line between melee and ranged is an artificial one fraught with difficult definitions. How about the case of a Chinese Chain Whip which strikes like a ranged weapon but is on a chain to be retrieved. Or the nunchuck which is one step more melee, having a single chain link between the sections instead of many. Or what about simply blowing sand in the enemy's eyes. Is that ranged?
If you're writing a fantasy story, magic can often handle this fuzzy line well. However, if you are looking for a harder form of fiction, magic may not be available to you.
My recommendation would be shifting from ontology to epistemology: change from worrying about "what kind of weapon is it" to "how does the weapon behave." It is much easier to define a clear way to stop behaviors of weapons than to stop weapons by name. Can you imagine a lifeforms which is resistant to Halberds but not Axes? It's hard. However, imagining a lifeforms which is resistant to stabbing but weak to crushing is not so hard to imagine (in many games, skeletons are weak to crushing, but virtually impervious to stabbing).
In fact, consider: in the last moments before impact, a bullet actually acts like a melee weapon, striking the body directly with enough force to tear tissue. Clearly we will need to define some behaviors
What are characteristics of ranged weapons that we might use:
- Distance from "wielder" to target.
- Usually relies on faster smaller projectiles
- Usually strikes a point, rather than a line (sword) or area (club). However, this behavior is identical to how a knife strikes a point (almost exactly identical), so we have to be careful with that.
- Beam weapons exist in many science fiction worlds. If they do, they either need to be handled separately, or in concert with any energy based melee weapons (lightsabers!)
Many have mentioned the Dune force shields. They work along this behavioral process. Fast moving objects larger than a few molecules cause the shield to raise up and repel everything until the fast moving object goes away. It relies on two behaviors I listed: distance to target and speed. If an object is close enough to be within the shield, it does nothing. If an object is moving slow enough to fool the shield (such as a well wielded knife), it does nothing. Herbert made this system of combat feel "alive" by intentionally sticking to behaviors the shield could do and then relying on the human element to fill in the combat styles needed to work with such a tool.
Another common lifeforms which is resilient to gunfire is the zombie. They tend to be resilient to gunfire because they have no small vulnerable areas like hearts or arteries to hit. However, their resiliency is limited: start tearing at them (such as removing the head) and very soon we find their limit.
And this is an important point: all immunities should have a limit. If they don't, they start to act funny fast. A zombie is STILL affected by a 20mm machine gun in many mythos' because the raw amount of trauma that round can put out is extraordinary. Even though they are "ranged," they strike with such ferocity that they act more like bludgeoning weapons to the zombies.
One approach to making the creatures more resilient to gunfire would be redundancy. Most living creatures are remarkably thrifty: most parts of our body are fed by one artery, and most muscles are innervated by one nerve. A creature which was more mesh-like in its structure would be much harder to kill with gunfire because it could rapidly adapt to those wounds. However, if you have a blade you can slice large swaths of mesh, dramatically increasing the chance of doing permanent damage. With a hammer you can ignore the weak points entirely and just bash on the musculature until it stops working.