What it looks like you're supposed to do is this: use the first three items of the medicine bag to control what items in other bags turn into.
If I'm reading what you wrote correctly, you're not changing bags, just what the item is. So of course when you change one, the other disappears. You need to use the medicine bag to not only change the item, but the bag compartment also. When you do it for Masterballs, change the bag compartment (second medicine item number) to the Key Items bag compartment.
Then change the item to an Exp. Share.
This isn't going to be exact, but in numbered list form:
While in the Medicine compartment:
- Press R+A to set the first three medicine counts item count to 1
- Modify the item bag (second medicine) to the Balls compartment
- Modify the item position (first medicine) to the Ball you want to change into Masterballs
- Modify the item id (third medicine) to Masterballs
- Modify the item bag (second medicine again) to the Key Items compartment
- Modify the item position (first medicine again) to the Key Item you want to change into the Exp. Share
- Modify the item id (third medicine again) to the Exp. Share
And that should do it. If this doesn't work, I dunno.