There are two ways to accomplish this.
If all you want to do is keep the variable state run to run, but not when power is lost, then add an Init Variables to the program and then you can choose the variable you want and tell it to keep its value from the last run.
The permanent way to do this is to add an installation variable. This variable will be available to any program that uses that installation file and would be persisted even after a power loss event such as powering down the robot. Only recommend these when its a variable that you do not ever want to lose its state regardless of power and it doesn't hurt to be available in other programs.
Im doing some testing with a UR5, and i am having a pop-up show at the start of the program asking the operator to input a number anywhere from 1 - 6. when the operator selects 1 or 2, that will instruct the robot to move to pick up either a green (1) or red (2) marker then im using switch cases to step through the rest of the program. After it picks up the marker, i have a variable called "TOOL_SELECT" and which ever marker is selected is the value. However whenever i stop and then restart the program, the value goes back to 0 then when i call the switch case to return whichever marker, it moves back to the home position instead of returning the marker. ( i have it returning home if the TOOL_SELECT variable had a 0) is there a way to keep the current marker selected? or is it always going to return to 0 after a stop?