Have you tried a proper transmission service, drain, re-fill and filter replacement? If it helps but not 100%, drive a couple hundred miles, then try it again.
The transmission shift decisions (when everything is working) is based on vehicle speed, engine load, and accelerator pedal position. so any problems with sensors associated with that could contributor (vehicle speed sensor, throttle position sensor, map or maf sensor). If all that’s working, there’s still selenoids in the transmission that could fail, and seals inside the trans could be leaking and the resultant loss of fluid pressure in certain circuits could prevent it from working correctly too. The transmission service suggested above might revive the seals, which is one reason to try it.