It helps to do the following test:
When the starter won't crank, while still holding the key in the start position, move the shift lever a little bit forward, just a little bit and see if the motor cranks. If not move the level a little bit backwards and see if the motor cranks.
If it cranks consistently when the lever is in one position but not when in the other, the control cable or possible the neutral switch need adjustment. The control cable gets adjusted at the motor.
What the preceding test is doing is checking that the level when in neutral is position in the detent of the control and activating the neutral switch
If neither position enable consistent work consistently but holding the switch in start and wiggling the levels back and forth a little does work, the switch is probably bad.
Replacing the switch can be challenging. It usually requires that the control box be opened up. Depending on you control model that may require the control to put be pulled out of the dash.
If you take the unit apart, take pictures of all the guts from several angles as you take it apart. Often things like cable ends and bushings can be installed in different holes and once you pull then out, you probably won't remember where they go back
Then of course you will need a new switch.
If the contacts are dirty, you might be able to clean up the internals of the switch with a spray contact cleaner.
Of course, while you are inspecting , look for loose wire connectors.