Match the job
A melting cheese, a grating cheese, and a fresh cheese are not interchangeable. Swap inside that job. A young Gouda can stand in for Gruyère in a melt. It will not stand in for Parmigiano-Reggiano over pasta.
Match texture and salt
A soft fresh cheese will not behave like a hard aged one. If the missing cheese is salty and dry, pick another salty dry cheese. If it is mild and moist, stay in that range. Moisture and age decide the melt.
Expect a change
A substitute changes the dish. Sheep's milk tastes fuller than cow's milk. A blue adds a sharp note that a firm cow cheese does not. Taste as you go, and add salt only after the cheese is in.