Initially the spheres A & B are at potential VA and VB. The potential of A when sphere B is earthed
Initially P.D. between A and B is VA - VB. After connecting to earth also P.D. between A and B is VA - VB but potential at B becomes zero, potential at A becomes VA - VB.