There is a rich selection of vba code to deal with pivot tables. Try doing what you are doing while recording a macro and see what you get.