2002 subaru legacy

when I have my AC on every once in awhile and sometimes more than others the car will suddenly buck and it seems to happen at different speeds and as soon as I turn the AC off it stops.

The AC may very well be cycling on and off. Your thermostat is set such that it runs the AC continuously, I take it, so it should not be turning off?
Subaru H6 engines (is yours a 4 or 6 cylinder engine) have a rev sensor that reports to the computer what speed the AC compressor is running at. If that sensor is failing, the AC will cycle erratically. That could cause the car to buck.

The one thing I figured out is that it only happens between 42 and 48 miles an hour no other speed Thanks

Better have a shop take a look at this. Something in the AC system – like the compressor or clutch – may be seizing up. If so, the sooner you fix it, the less $$$ it will be. Assuming you live in temperate northern hemisphere, so now is a good time for AC repair as you don’t need it, right?